Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 3 | #include <linux/module.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 4 | #include <linux/err.h> |
| 5 | #include <linux/highmem.h> |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/pagemap.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/uaccess.h> |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 10 | #ifdef CONFIG_BLOCK |
| 11 | #include <linux/bio.h> |
| 12 | #endif |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 13 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 14 | #include <linux/ceph/libceph.h> |
| 15 | #include <linux/ceph/osd_client.h> |
| 16 | #include <linux/ceph/messenger.h> |
| 17 | #include <linux/ceph/decode.h> |
| 18 | #include <linux/ceph/auth.h> |
| 19 | #include <linux/ceph/pagelist.h> |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 20 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 21 | #define OSD_OP_FRONT_LEN 4096 |
| 22 | #define OSD_OPREPLY_FRONT_LEN 512 |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 23 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 24 | static const struct ceph_connection_operations osd_con_ops; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 25 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 26 | static void send_queued(struct ceph_osd_client *osdc); |
| 27 | static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 28 | static void __register_request(struct ceph_osd_client *osdc, |
| 29 | struct ceph_osd_request *req); |
| 30 | static void __unregister_linger_request(struct ceph_osd_client *osdc, |
| 31 | struct ceph_osd_request *req); |
Sage Weil | 56e925b | 2012-01-03 12:34:34 -0800 | [diff] [blame] | 32 | static void __send_request(struct ceph_osd_client *osdc, |
| 33 | struct ceph_osd_request *req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 34 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 35 | static int op_needs_trail(int op) |
| 36 | { |
| 37 | switch (op) { |
| 38 | case CEPH_OSD_OP_GETXATTR: |
| 39 | case CEPH_OSD_OP_SETXATTR: |
| 40 | case CEPH_OSD_OP_CMPXATTR: |
| 41 | case CEPH_OSD_OP_CALL: |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 42 | case CEPH_OSD_OP_NOTIFY: |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 43 | return 1; |
| 44 | default: |
| 45 | return 0; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static int op_has_extent(int op) |
| 50 | { |
| 51 | return (op == CEPH_OSD_OP_READ || |
| 52 | op == CEPH_OSD_OP_WRITE); |
| 53 | } |
| 54 | |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 55 | int ceph_calc_raw_layout(struct ceph_osd_client *osdc, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 56 | struct ceph_file_layout *layout, |
| 57 | u64 snapid, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 58 | u64 off, u64 *plen, u64 *bno, |
| 59 | struct ceph_osd_request *req, |
| 60 | struct ceph_osd_req_op *op) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 61 | { |
| 62 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 63 | u64 orig_len = *plen; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 64 | u64 objoff, objlen; /* extent in object */ |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 65 | int r; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 66 | |
| 67 | reqhead->snapid = cpu_to_le64(snapid); |
| 68 | |
| 69 | /* object extent? */ |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 70 | r = ceph_calc_file_object_mapping(layout, off, plen, bno, |
| 71 | &objoff, &objlen); |
| 72 | if (r < 0) |
| 73 | return r; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 74 | if (*plen < orig_len) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 75 | dout(" skipping last %llu, final file extent %llu~%llu\n", |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 76 | orig_len - *plen, off, *plen); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 77 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 78 | if (op_has_extent(op->op)) { |
| 79 | op->extent.offset = objoff; |
| 80 | op->extent.length = objlen; |
| 81 | } |
| 82 | req->r_num_pages = calc_pages_for(off, *plen); |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 83 | req->r_page_alignment = off & ~PAGE_MASK; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 84 | if (op->op == CEPH_OSD_OP_WRITE) |
| 85 | op->payload_len = *plen; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 86 | |
| 87 | dout("calc_layout bno=%llx %llu~%llu (%d pages)\n", |
| 88 | *bno, objoff, objlen, req->r_num_pages); |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 89 | return 0; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 90 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 91 | EXPORT_SYMBOL(ceph_calc_raw_layout); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 92 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 93 | /* |
| 94 | * Implement client access to distributed object storage cluster. |
| 95 | * |
| 96 | * All data objects are stored within a cluster/cloud of OSDs, or |
| 97 | * "object storage devices." (Note that Ceph OSDs have _nothing_ to |
| 98 | * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply |
| 99 | * remote daemons serving up and coordinating consistent and safe |
| 100 | * access to storage. |
| 101 | * |
| 102 | * Cluster membership and the mapping of data objects onto storage devices |
| 103 | * are described by the osd map. |
| 104 | * |
| 105 | * We keep track of pending OSD requests (read, write), resubmit |
| 106 | * requests to different OSDs when the cluster topology/data layout |
| 107 | * change, or retry the affected requests when the communications |
| 108 | * channel with an OSD is reset. |
| 109 | */ |
| 110 | |
| 111 | /* |
| 112 | * calculate the mapping of a file extent onto an object, and fill out the |
| 113 | * request accordingly. shorten extent as necessary if it crosses an |
| 114 | * object boundary. |
| 115 | * |
| 116 | * fill osd op in request message. |
| 117 | */ |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 118 | static int calc_layout(struct ceph_osd_client *osdc, |
| 119 | struct ceph_vino vino, |
| 120 | struct ceph_file_layout *layout, |
| 121 | u64 off, u64 *plen, |
| 122 | struct ceph_osd_request *req, |
| 123 | struct ceph_osd_req_op *op) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 124 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 125 | u64 bno; |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 126 | int r; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 127 | |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 128 | r = ceph_calc_raw_layout(osdc, layout, vino.snap, off, |
| 129 | plen, &bno, req, op); |
| 130 | if (r < 0) |
| 131 | return r; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 132 | |
Sage Weil | 2dab036 | 2011-05-12 14:29:51 -0700 | [diff] [blame] | 133 | snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 134 | req->r_oid_len = strlen(req->r_oid); |
Sage Weil | d63b77f | 2012-09-24 20:59:48 -0700 | [diff] [blame^] | 135 | |
| 136 | return r; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 139 | /* |
| 140 | * requests |
| 141 | */ |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 142 | void ceph_osdc_release_request(struct kref *kref) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 143 | { |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 144 | struct ceph_osd_request *req = container_of(kref, |
| 145 | struct ceph_osd_request, |
| 146 | r_kref); |
| 147 | |
| 148 | if (req->r_request) |
| 149 | ceph_msg_put(req->r_request); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 150 | if (req->r_con_filling_msg) { |
Alex Elder | 8921d11 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 151 | dout("%s revoking pages %p from con %p\n", __func__, |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 152 | req->r_pages, req->r_con_filling_msg); |
Alex Elder | 8921d11 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 153 | ceph_msg_revoke_incoming(req->r_reply); |
Sage Weil | 0d47766 | 2012-05-31 20:22:18 -0700 | [diff] [blame] | 154 | req->r_con_filling_msg->ops->put(req->r_con_filling_msg); |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 155 | } |
Alex Elder | ab8cb34 | 2012-06-04 14:43:32 -0500 | [diff] [blame] | 156 | if (req->r_reply) |
| 157 | ceph_msg_put(req->r_reply); |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 158 | if (req->r_own_pages) |
| 159 | ceph_release_page_vector(req->r_pages, |
| 160 | req->r_num_pages); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 161 | #ifdef CONFIG_BLOCK |
| 162 | if (req->r_bio) |
| 163 | bio_put(req->r_bio); |
| 164 | #endif |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 165 | ceph_put_snap_context(req->r_snapc); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 166 | if (req->r_trail) { |
| 167 | ceph_pagelist_release(req->r_trail); |
| 168 | kfree(req->r_trail); |
| 169 | } |
Sage Weil | 415e49a | 2009-12-07 13:37:03 -0800 | [diff] [blame] | 170 | if (req->r_mempool) |
| 171 | mempool_free(req, req->r_osdc->req_mempool); |
| 172 | else |
| 173 | kfree(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 174 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 175 | EXPORT_SYMBOL(ceph_osdc_release_request); |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 176 | |
| 177 | static int get_num_ops(struct ceph_osd_req_op *ops, int *needs_trail) |
| 178 | { |
| 179 | int i = 0; |
| 180 | |
| 181 | if (needs_trail) |
| 182 | *needs_trail = 0; |
| 183 | while (ops[i].op) { |
| 184 | if (needs_trail && op_needs_trail(ops[i].op)) |
| 185 | *needs_trail = 1; |
| 186 | i++; |
| 187 | } |
| 188 | |
| 189 | return i; |
| 190 | } |
| 191 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 192 | struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, |
| 193 | int flags, |
| 194 | struct ceph_snap_context *snapc, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 195 | struct ceph_osd_req_op *ops, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 196 | bool use_mempool, |
| 197 | gfp_t gfp_flags, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 198 | struct page **pages, |
| 199 | struct bio *bio) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 200 | { |
| 201 | struct ceph_osd_request *req; |
| 202 | struct ceph_msg *msg; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 203 | int needs_trail; |
| 204 | int num_op = get_num_ops(ops, &needs_trail); |
| 205 | size_t msg_size = sizeof(struct ceph_osd_request_head); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 206 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 207 | msg_size += num_op*sizeof(struct ceph_osd_op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 208 | |
| 209 | if (use_mempool) { |
| 210 | req = mempool_alloc(osdc->req_mempool, gfp_flags); |
| 211 | memset(req, 0, sizeof(*req)); |
| 212 | } else { |
| 213 | req = kzalloc(sizeof(*req), gfp_flags); |
| 214 | } |
| 215 | if (req == NULL) |
| 216 | return NULL; |
| 217 | |
| 218 | req->r_osdc = osdc; |
| 219 | req->r_mempool = use_mempool; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 220 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 221 | kref_init(&req->r_kref); |
| 222 | init_completion(&req->r_completion); |
| 223 | init_completion(&req->r_safe_completion); |
Sage Weil | cd43045 | 2012-07-09 14:31:41 -0700 | [diff] [blame] | 224 | rb_init_node(&req->r_node); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 225 | INIT_LIST_HEAD(&req->r_unsafe_item); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 226 | INIT_LIST_HEAD(&req->r_linger_item); |
| 227 | INIT_LIST_HEAD(&req->r_linger_osd); |
Sage Weil | 935b639 | 2011-09-16 11:13:17 -0700 | [diff] [blame] | 228 | INIT_LIST_HEAD(&req->r_req_lru_item); |
Sage Weil | cd43045 | 2012-07-09 14:31:41 -0700 | [diff] [blame] | 229 | INIT_LIST_HEAD(&req->r_osd_item); |
| 230 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 231 | req->r_flags = flags; |
| 232 | |
| 233 | WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0); |
| 234 | |
| 235 | /* create reply message */ |
| 236 | if (use_mempool) |
| 237 | msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0); |
| 238 | else |
| 239 | msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 240 | OSD_OPREPLY_FRONT_LEN, gfp_flags, true); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 241 | if (!msg) { |
| 242 | ceph_osdc_put_request(req); |
| 243 | return NULL; |
| 244 | } |
| 245 | req->r_reply = msg; |
| 246 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 247 | /* allocate space for the trailing data */ |
| 248 | if (needs_trail) { |
| 249 | req->r_trail = kmalloc(sizeof(struct ceph_pagelist), gfp_flags); |
| 250 | if (!req->r_trail) { |
| 251 | ceph_osdc_put_request(req); |
| 252 | return NULL; |
| 253 | } |
| 254 | ceph_pagelist_init(req->r_trail); |
| 255 | } |
Sage Weil | d50b409 | 2012-07-09 14:22:34 -0700 | [diff] [blame] | 256 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 257 | /* create request message; allow space for oid */ |
Stratos Psomadakis | 224736d | 2011-11-10 15:45:37 +0200 | [diff] [blame] | 258 | msg_size += MAX_OBJ_NAME_SIZE; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 259 | if (snapc) |
| 260 | msg_size += sizeof(u64) * snapc->num_snaps; |
| 261 | if (use_mempool) |
| 262 | msg = ceph_msgpool_get(&osdc->msgpool_op, 0); |
| 263 | else |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 264 | msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 265 | if (!msg) { |
| 266 | ceph_osdc_put_request(req); |
| 267 | return NULL; |
| 268 | } |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 269 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 270 | memset(msg->front.iov_base, 0, msg->front.iov_len); |
| 271 | |
| 272 | req->r_request = msg; |
| 273 | req->r_pages = pages; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 274 | #ifdef CONFIG_BLOCK |
| 275 | if (bio) { |
| 276 | req->r_bio = bio; |
| 277 | bio_get(req->r_bio); |
| 278 | } |
| 279 | #endif |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 280 | |
| 281 | return req; |
| 282 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 283 | EXPORT_SYMBOL(ceph_osdc_alloc_request); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 284 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 285 | static void osd_req_encode_op(struct ceph_osd_request *req, |
| 286 | struct ceph_osd_op *dst, |
| 287 | struct ceph_osd_req_op *src) |
| 288 | { |
| 289 | dst->op = cpu_to_le16(src->op); |
| 290 | |
Alex Elder | 065a68f | 2012-04-20 15:49:43 -0500 | [diff] [blame] | 291 | switch (src->op) { |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 292 | case CEPH_OSD_OP_READ: |
| 293 | case CEPH_OSD_OP_WRITE: |
| 294 | dst->extent.offset = |
| 295 | cpu_to_le64(src->extent.offset); |
| 296 | dst->extent.length = |
| 297 | cpu_to_le64(src->extent.length); |
| 298 | dst->extent.truncate_size = |
| 299 | cpu_to_le64(src->extent.truncate_size); |
| 300 | dst->extent.truncate_seq = |
| 301 | cpu_to_le32(src->extent.truncate_seq); |
| 302 | break; |
| 303 | |
| 304 | case CEPH_OSD_OP_GETXATTR: |
| 305 | case CEPH_OSD_OP_SETXATTR: |
| 306 | case CEPH_OSD_OP_CMPXATTR: |
| 307 | BUG_ON(!req->r_trail); |
| 308 | |
| 309 | dst->xattr.name_len = cpu_to_le32(src->xattr.name_len); |
| 310 | dst->xattr.value_len = cpu_to_le32(src->xattr.value_len); |
| 311 | dst->xattr.cmp_op = src->xattr.cmp_op; |
| 312 | dst->xattr.cmp_mode = src->xattr.cmp_mode; |
| 313 | ceph_pagelist_append(req->r_trail, src->xattr.name, |
| 314 | src->xattr.name_len); |
| 315 | ceph_pagelist_append(req->r_trail, src->xattr.val, |
| 316 | src->xattr.value_len); |
| 317 | break; |
Yehuda Sadeh | ae1533b | 2010-05-18 16:38:08 -0700 | [diff] [blame] | 318 | case CEPH_OSD_OP_CALL: |
| 319 | BUG_ON(!req->r_trail); |
| 320 | |
| 321 | dst->cls.class_len = src->cls.class_len; |
| 322 | dst->cls.method_len = src->cls.method_len; |
| 323 | dst->cls.indata_len = cpu_to_le32(src->cls.indata_len); |
| 324 | |
| 325 | ceph_pagelist_append(req->r_trail, src->cls.class_name, |
| 326 | src->cls.class_len); |
| 327 | ceph_pagelist_append(req->r_trail, src->cls.method_name, |
| 328 | src->cls.method_len); |
| 329 | ceph_pagelist_append(req->r_trail, src->cls.indata, |
| 330 | src->cls.indata_len); |
| 331 | break; |
| 332 | case CEPH_OSD_OP_ROLLBACK: |
| 333 | dst->snap.snapid = cpu_to_le64(src->snap.snapid); |
| 334 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 335 | case CEPH_OSD_OP_STARTSYNC: |
| 336 | break; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 337 | case CEPH_OSD_OP_NOTIFY: |
| 338 | { |
| 339 | __le32 prot_ver = cpu_to_le32(src->watch.prot_ver); |
| 340 | __le32 timeout = cpu_to_le32(src->watch.timeout); |
| 341 | |
| 342 | BUG_ON(!req->r_trail); |
| 343 | |
| 344 | ceph_pagelist_append(req->r_trail, |
| 345 | &prot_ver, sizeof(prot_ver)); |
| 346 | ceph_pagelist_append(req->r_trail, |
| 347 | &timeout, sizeof(timeout)); |
| 348 | } |
| 349 | case CEPH_OSD_OP_NOTIFY_ACK: |
| 350 | case CEPH_OSD_OP_WATCH: |
| 351 | dst->watch.cookie = cpu_to_le64(src->watch.cookie); |
| 352 | dst->watch.ver = cpu_to_le64(src->watch.ver); |
| 353 | dst->watch.flag = src->watch.flag; |
| 354 | break; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 355 | default: |
| 356 | pr_err("unrecognized osd opcode %d\n", dst->op); |
| 357 | WARN_ON(1); |
| 358 | break; |
| 359 | } |
| 360 | dst->payload_len = cpu_to_le32(src->payload_len); |
| 361 | } |
| 362 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 363 | /* |
| 364 | * build new request AND message |
| 365 | * |
| 366 | */ |
| 367 | void ceph_osdc_build_request(struct ceph_osd_request *req, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 368 | u64 off, u64 *plen, |
| 369 | struct ceph_osd_req_op *src_ops, |
| 370 | struct ceph_snap_context *snapc, |
| 371 | struct timespec *mtime, |
| 372 | const char *oid, |
| 373 | int oid_len) |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 374 | { |
| 375 | struct ceph_msg *msg = req->r_request; |
| 376 | struct ceph_osd_request_head *head; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 377 | struct ceph_osd_req_op *src_op; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 378 | struct ceph_osd_op *op; |
| 379 | void *p; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 380 | int num_op = get_num_ops(src_ops, NULL); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 381 | size_t msg_size = sizeof(*head) + num_op*sizeof(*op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 382 | int flags = req->r_flags; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 383 | u64 data_len = 0; |
| 384 | int i; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 385 | |
| 386 | head = msg->front.iov_base; |
| 387 | op = (void *)(head + 1); |
| 388 | p = (void *)(op + num_op); |
| 389 | |
| 390 | req->r_snapc = ceph_get_snap_context(snapc); |
| 391 | |
| 392 | head->client_inc = cpu_to_le32(1); /* always, for now. */ |
| 393 | head->flags = cpu_to_le32(flags); |
| 394 | if (flags & CEPH_OSD_FLAG_WRITE) |
| 395 | ceph_encode_timespec(&head->mtime, mtime); |
| 396 | head->num_ops = cpu_to_le16(num_op); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 397 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 398 | |
| 399 | /* fill in oid */ |
| 400 | head->object_len = cpu_to_le32(oid_len); |
| 401 | memcpy(p, oid, oid_len); |
| 402 | p += oid_len; |
| 403 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 404 | src_op = src_ops; |
| 405 | while (src_op->op) { |
| 406 | osd_req_encode_op(req, op, src_op); |
| 407 | src_op++; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 408 | op++; |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 409 | } |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 410 | |
| 411 | if (req->r_trail) |
| 412 | data_len += req->r_trail->length; |
| 413 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 414 | if (snapc) { |
| 415 | head->snap_seq = cpu_to_le64(snapc->seq); |
| 416 | head->num_snaps = cpu_to_le32(snapc->num_snaps); |
| 417 | for (i = 0; i < snapc->num_snaps; i++) { |
| 418 | put_unaligned_le64(snapc->snaps[i], p); |
| 419 | p += sizeof(u64); |
| 420 | } |
| 421 | } |
| 422 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 423 | if (flags & CEPH_OSD_FLAG_WRITE) { |
| 424 | req->r_request->hdr.data_off = cpu_to_le16(off); |
| 425 | req->r_request->hdr.data_len = cpu_to_le32(*plen + data_len); |
| 426 | } else if (data_len) { |
| 427 | req->r_request->hdr.data_off = 0; |
| 428 | req->r_request->hdr.data_len = cpu_to_le32(data_len); |
| 429 | } |
| 430 | |
Sage Weil | c5c6b19 | 2010-11-09 12:40:00 -0800 | [diff] [blame] | 431 | req->r_request->page_alignment = req->r_page_alignment; |
| 432 | |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 433 | BUG_ON(p > msg->front.iov_base + msg->front.iov_len); |
| 434 | msg_size = p - msg->front.iov_base; |
| 435 | msg->front.iov_len = msg_size; |
| 436 | msg->hdr.front_len = cpu_to_le32(msg_size); |
| 437 | return; |
| 438 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 439 | EXPORT_SYMBOL(ceph_osdc_build_request); |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 440 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 441 | /* |
| 442 | * build new request AND message, calculate layout, and adjust file |
| 443 | * extent as needed. |
| 444 | * |
| 445 | * if the file was recently truncated, we include information about its |
| 446 | * old and new size so that the object can be updated appropriately. (we |
| 447 | * avoid synchronously deleting truncated objects because it's slow.) |
| 448 | * |
| 449 | * if @do_sync, include a 'startsync' command so that the osd will flush |
| 450 | * data quickly. |
| 451 | */ |
| 452 | struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, |
| 453 | struct ceph_file_layout *layout, |
| 454 | struct ceph_vino vino, |
| 455 | u64 off, u64 *plen, |
| 456 | int opcode, int flags, |
| 457 | struct ceph_snap_context *snapc, |
| 458 | int do_sync, |
| 459 | u32 truncate_seq, |
| 460 | u64 truncate_size, |
| 461 | struct timespec *mtime, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 462 | bool use_mempool, int num_reply, |
| 463 | int page_align) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 464 | { |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 465 | struct ceph_osd_req_op ops[3]; |
| 466 | struct ceph_osd_request *req; |
| 467 | |
| 468 | ops[0].op = opcode; |
| 469 | ops[0].extent.truncate_seq = truncate_seq; |
| 470 | ops[0].extent.truncate_size = truncate_size; |
| 471 | ops[0].payload_len = 0; |
| 472 | |
| 473 | if (do_sync) { |
| 474 | ops[1].op = CEPH_OSD_OP_STARTSYNC; |
| 475 | ops[1].payload_len = 0; |
| 476 | ops[2].op = 0; |
| 477 | } else |
| 478 | ops[1].op = 0; |
| 479 | |
| 480 | req = ceph_osdc_alloc_request(osdc, flags, |
| 481 | snapc, ops, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 482 | use_mempool, |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 483 | GFP_NOFS, NULL, NULL); |
Sage Weil | 4ad1262 | 2011-05-03 09:23:36 -0700 | [diff] [blame] | 484 | if (!req) |
| 485 | return NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 486 | |
| 487 | /* calculate max write size */ |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 488 | calc_layout(osdc, vino, layout, off, plen, req, ops); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 489 | req->r_file_layout = *layout; /* keep a copy */ |
| 490 | |
Sage Weil | 9bb0ce2 | 2011-06-13 16:20:18 -0700 | [diff] [blame] | 491 | /* in case it differs from natural (file) alignment that |
| 492 | calc_layout filled in for us */ |
| 493 | req->r_num_pages = calc_pages_for(page_align, *plen); |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 494 | req->r_page_alignment = page_align; |
| 495 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 496 | ceph_osdc_build_request(req, off, plen, ops, |
| 497 | snapc, |
Yehuda Sadeh | 3499e8a | 2010-04-06 14:51:47 -0700 | [diff] [blame] | 498 | mtime, |
| 499 | req->r_oid, req->r_oid_len); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 500 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 501 | return req; |
| 502 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 503 | EXPORT_SYMBOL(ceph_osdc_new_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 504 | |
| 505 | /* |
| 506 | * We keep osd requests in an rbtree, sorted by ->r_tid. |
| 507 | */ |
| 508 | static void __insert_request(struct ceph_osd_client *osdc, |
| 509 | struct ceph_osd_request *new) |
| 510 | { |
| 511 | struct rb_node **p = &osdc->requests.rb_node; |
| 512 | struct rb_node *parent = NULL; |
| 513 | struct ceph_osd_request *req = NULL; |
| 514 | |
| 515 | while (*p) { |
| 516 | parent = *p; |
| 517 | req = rb_entry(parent, struct ceph_osd_request, r_node); |
| 518 | if (new->r_tid < req->r_tid) |
| 519 | p = &(*p)->rb_left; |
| 520 | else if (new->r_tid > req->r_tid) |
| 521 | p = &(*p)->rb_right; |
| 522 | else |
| 523 | BUG(); |
| 524 | } |
| 525 | |
| 526 | rb_link_node(&new->r_node, parent, p); |
| 527 | rb_insert_color(&new->r_node, &osdc->requests); |
| 528 | } |
| 529 | |
| 530 | static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc, |
| 531 | u64 tid) |
| 532 | { |
| 533 | struct ceph_osd_request *req; |
| 534 | struct rb_node *n = osdc->requests.rb_node; |
| 535 | |
| 536 | while (n) { |
| 537 | req = rb_entry(n, struct ceph_osd_request, r_node); |
| 538 | if (tid < req->r_tid) |
| 539 | n = n->rb_left; |
| 540 | else if (tid > req->r_tid) |
| 541 | n = n->rb_right; |
| 542 | else |
| 543 | return req; |
| 544 | } |
| 545 | return NULL; |
| 546 | } |
| 547 | |
| 548 | static struct ceph_osd_request * |
| 549 | __lookup_request_ge(struct ceph_osd_client *osdc, |
| 550 | u64 tid) |
| 551 | { |
| 552 | struct ceph_osd_request *req; |
| 553 | struct rb_node *n = osdc->requests.rb_node; |
| 554 | |
| 555 | while (n) { |
| 556 | req = rb_entry(n, struct ceph_osd_request, r_node); |
| 557 | if (tid < req->r_tid) { |
| 558 | if (!n->rb_left) |
| 559 | return req; |
| 560 | n = n->rb_left; |
| 561 | } else if (tid > req->r_tid) { |
| 562 | n = n->rb_right; |
| 563 | } else { |
| 564 | return req; |
| 565 | } |
| 566 | } |
| 567 | return NULL; |
| 568 | } |
| 569 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 570 | /* |
| 571 | * Resubmit requests pending on the given osd. |
| 572 | */ |
| 573 | static void __kick_osd_requests(struct ceph_osd_client *osdc, |
| 574 | struct ceph_osd *osd) |
| 575 | { |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 576 | struct ceph_osd_request *req, *nreq; |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 577 | int err; |
| 578 | |
| 579 | dout("__kick_osd_requests osd%d\n", osd->o_osd); |
| 580 | err = __reset_osd(osdc, osd); |
| 581 | if (err == -EAGAIN) |
| 582 | return; |
| 583 | |
| 584 | list_for_each_entry(req, &osd->o_requests, r_osd_item) { |
| 585 | list_move(&req->r_req_lru_item, &osdc->req_unsent); |
| 586 | dout("requeued %p tid %llu osd%d\n", req, req->r_tid, |
| 587 | osd->o_osd); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 588 | if (!req->r_linger) |
| 589 | req->r_flags |= CEPH_OSD_FLAG_RETRY; |
| 590 | } |
| 591 | |
| 592 | list_for_each_entry_safe(req, nreq, &osd->o_linger_requests, |
| 593 | r_linger_osd) { |
Sage Weil | 77f38e0 | 2011-04-06 09:09:16 -0700 | [diff] [blame] | 594 | /* |
| 595 | * reregister request prior to unregistering linger so |
| 596 | * that r_osd is preserved. |
| 597 | */ |
| 598 | BUG_ON(!list_empty(&req->r_req_lru_item)); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 599 | __register_request(osdc, req); |
Sage Weil | 77f38e0 | 2011-04-06 09:09:16 -0700 | [diff] [blame] | 600 | list_add(&req->r_req_lru_item, &osdc->req_unsent); |
| 601 | list_add(&req->r_osd_item, &req->r_osd->o_requests); |
| 602 | __unregister_linger_request(osdc, req); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 603 | dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid, |
| 604 | osd->o_osd); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | static void kick_osd_requests(struct ceph_osd_client *osdc, |
| 609 | struct ceph_osd *kickosd) |
| 610 | { |
| 611 | mutex_lock(&osdc->request_mutex); |
| 612 | __kick_osd_requests(osdc, kickosd); |
| 613 | mutex_unlock(&osdc->request_mutex); |
| 614 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 615 | |
| 616 | /* |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 617 | * If the osd connection drops, we need to resubmit all requests. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 618 | */ |
| 619 | static void osd_reset(struct ceph_connection *con) |
| 620 | { |
| 621 | struct ceph_osd *osd = con->private; |
| 622 | struct ceph_osd_client *osdc; |
| 623 | |
| 624 | if (!osd) |
| 625 | return; |
| 626 | dout("osd_reset osd%d\n", osd->o_osd); |
| 627 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 628 | down_read(&osdc->map_sem); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 629 | kick_osd_requests(osdc, osd); |
| 630 | send_queued(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 631 | up_read(&osdc->map_sem); |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * Track open sessions with osds. |
| 636 | */ |
Alex Elder | e10006f | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 637 | 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] | 638 | { |
| 639 | struct ceph_osd *osd; |
| 640 | |
| 641 | osd = kzalloc(sizeof(*osd), GFP_NOFS); |
| 642 | if (!osd) |
| 643 | return NULL; |
| 644 | |
| 645 | atomic_set(&osd->o_ref, 1); |
| 646 | osd->o_osdc = osdc; |
Alex Elder | e10006f | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 647 | osd->o_osd = onum; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 648 | INIT_LIST_HEAD(&osd->o_requests); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 649 | INIT_LIST_HEAD(&osd->o_linger_requests); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 650 | INIT_LIST_HEAD(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 651 | osd->o_incarnation = 1; |
| 652 | |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 653 | 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] | 654 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 655 | INIT_LIST_HEAD(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 656 | return osd; |
| 657 | } |
| 658 | |
| 659 | static struct ceph_osd *get_osd(struct ceph_osd *osd) |
| 660 | { |
| 661 | if (atomic_inc_not_zero(&osd->o_ref)) { |
| 662 | dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1, |
| 663 | atomic_read(&osd->o_ref)); |
| 664 | return osd; |
| 665 | } else { |
| 666 | dout("get_osd %p FAIL\n", osd); |
| 667 | return NULL; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | static void put_osd(struct ceph_osd *osd) |
| 672 | { |
| 673 | dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref), |
| 674 | atomic_read(&osd->o_ref) - 1); |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 675 | if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) { |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 676 | struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; |
| 677 | |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 678 | if (ac->ops && ac->ops->destroy_authorizer) |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 679 | ac->ops->destroy_authorizer(ac, osd->o_auth.authorizer); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 680 | kfree(osd); |
Sage Weil | 79494d1 | 2010-05-27 14:15:49 -0700 | [diff] [blame] | 681 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /* |
| 685 | * remove an osd from our map |
| 686 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 687 | static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 688 | { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 689 | dout("__remove_osd %p\n", osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 690 | BUG_ON(!list_empty(&osd->o_requests)); |
| 691 | rb_erase(&osd->o_node, &osdc->osds); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 692 | list_del_init(&osd->o_osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 693 | ceph_con_close(&osd->o_con); |
| 694 | put_osd(osd); |
| 695 | } |
| 696 | |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 697 | static void remove_all_osds(struct ceph_osd_client *osdc) |
| 698 | { |
Jiaju Zhang | 048a9d2 | 2012-07-20 08:18:36 -0500 | [diff] [blame] | 699 | dout("%s %p\n", __func__, osdc); |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 700 | mutex_lock(&osdc->request_mutex); |
| 701 | while (!RB_EMPTY_ROOT(&osdc->osds)) { |
| 702 | struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds), |
| 703 | struct ceph_osd, o_node); |
| 704 | __remove_osd(osdc, osd); |
| 705 | } |
| 706 | mutex_unlock(&osdc->request_mutex); |
| 707 | } |
| 708 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 709 | static void __move_osd_to_lru(struct ceph_osd_client *osdc, |
| 710 | struct ceph_osd *osd) |
| 711 | { |
| 712 | dout("__move_osd_to_lru %p\n", osd); |
| 713 | BUG_ON(!list_empty(&osd->o_osd_lru)); |
| 714 | list_add_tail(&osd->o_osd_lru, &osdc->osd_lru); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 715 | osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static void __remove_osd_from_lru(struct ceph_osd *osd) |
| 719 | { |
| 720 | dout("__remove_osd_from_lru %p\n", osd); |
| 721 | if (!list_empty(&osd->o_osd_lru)) |
| 722 | list_del_init(&osd->o_osd_lru); |
| 723 | } |
| 724 | |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 725 | static void remove_old_osds(struct ceph_osd_client *osdc) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 726 | { |
| 727 | struct ceph_osd *osd, *nosd; |
| 728 | |
| 729 | dout("__remove_old_osds %p\n", osdc); |
| 730 | mutex_lock(&osdc->request_mutex); |
| 731 | list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) { |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 732 | if (time_before(jiffies, osd->lru_ttl)) |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 733 | break; |
| 734 | __remove_osd(osdc, osd); |
| 735 | } |
| 736 | mutex_unlock(&osdc->request_mutex); |
| 737 | } |
| 738 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 739 | /* |
| 740 | * reset osd connect |
| 741 | */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 742 | static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 743 | { |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 744 | struct ceph_osd_request *req; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 745 | int ret = 0; |
| 746 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 747 | dout("__reset_osd %p osd%d\n", osd, osd->o_osd); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 748 | if (list_empty(&osd->o_requests) && |
| 749 | list_empty(&osd->o_linger_requests)) { |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 750 | __remove_osd(osdc, osd); |
Sage Weil | 87b315a | 2010-03-22 14:51:18 -0700 | [diff] [blame] | 751 | } else if (memcmp(&osdc->osdmap->osd_addr[osd->o_osd], |
| 752 | &osd->o_con.peer_addr, |
| 753 | sizeof(osd->o_con.peer_addr)) == 0 && |
| 754 | !ceph_con_opened(&osd->o_con)) { |
| 755 | dout(" osd addr hasn't changed and connection never opened," |
| 756 | " letting msgr retry"); |
| 757 | /* touch each r_stamp for handle_timeout()'s benfit */ |
| 758 | list_for_each_entry(req, &osd->o_requests, r_osd_item) |
| 759 | req->r_stamp = jiffies; |
| 760 | ret = -EAGAIN; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 761 | } else { |
| 762 | ceph_con_close(&osd->o_con); |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 763 | ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, |
| 764 | &osdc->osdmap->osd_addr[osd->o_osd]); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 765 | osd->o_incarnation++; |
| 766 | } |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new) |
| 771 | { |
| 772 | struct rb_node **p = &osdc->osds.rb_node; |
| 773 | struct rb_node *parent = NULL; |
| 774 | struct ceph_osd *osd = NULL; |
| 775 | |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 776 | dout("__insert_osd %p osd%d\n", new, new->o_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 777 | while (*p) { |
| 778 | parent = *p; |
| 779 | osd = rb_entry(parent, struct ceph_osd, o_node); |
| 780 | if (new->o_osd < osd->o_osd) |
| 781 | p = &(*p)->rb_left; |
| 782 | else if (new->o_osd > osd->o_osd) |
| 783 | p = &(*p)->rb_right; |
| 784 | else |
| 785 | BUG(); |
| 786 | } |
| 787 | |
| 788 | rb_link_node(&new->o_node, parent, p); |
| 789 | rb_insert_color(&new->o_node, &osdc->osds); |
| 790 | } |
| 791 | |
| 792 | static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o) |
| 793 | { |
| 794 | struct ceph_osd *osd; |
| 795 | struct rb_node *n = osdc->osds.rb_node; |
| 796 | |
| 797 | while (n) { |
| 798 | osd = rb_entry(n, struct ceph_osd, o_node); |
| 799 | if (o < osd->o_osd) |
| 800 | n = n->rb_left; |
| 801 | else if (o > osd->o_osd) |
| 802 | n = n->rb_right; |
| 803 | else |
| 804 | return osd; |
| 805 | } |
| 806 | return NULL; |
| 807 | } |
| 808 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 809 | static void __schedule_osd_timeout(struct ceph_osd_client *osdc) |
| 810 | { |
| 811 | schedule_delayed_work(&osdc->timeout_work, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 812 | osdc->client->options->osd_keepalive_timeout * HZ); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static void __cancel_osd_timeout(struct ceph_osd_client *osdc) |
| 816 | { |
| 817 | cancel_delayed_work(&osdc->timeout_work); |
| 818 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 819 | |
| 820 | /* |
| 821 | * Register request, assign tid. If this is the first request, set up |
| 822 | * the timeout event. |
| 823 | */ |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 824 | static void __register_request(struct ceph_osd_client *osdc, |
| 825 | struct ceph_osd_request *req) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 826 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 827 | req->r_tid = ++osdc->last_tid; |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 828 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); |
Sage Weil | 77f38e0 | 2011-04-06 09:09:16 -0700 | [diff] [blame] | 829 | dout("__register_request %p tid %lld\n", req, req->r_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 830 | __insert_request(osdc, req); |
| 831 | ceph_osdc_get_request(req); |
| 832 | osdc->num_requests++; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 833 | if (osdc->num_requests == 1) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 834 | dout(" first request, scheduling timeout\n"); |
| 835 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 836 | } |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | static void register_request(struct ceph_osd_client *osdc, |
| 840 | struct ceph_osd_request *req) |
| 841 | { |
| 842 | mutex_lock(&osdc->request_mutex); |
| 843 | __register_request(osdc, req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 844 | mutex_unlock(&osdc->request_mutex); |
| 845 | } |
| 846 | |
| 847 | /* |
| 848 | * called under osdc->request_mutex |
| 849 | */ |
| 850 | static void __unregister_request(struct ceph_osd_client *osdc, |
| 851 | struct ceph_osd_request *req) |
| 852 | { |
Sage Weil | 35f9f8a | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 853 | if (RB_EMPTY_NODE(&req->r_node)) { |
| 854 | dout("__unregister_request %p tid %lld not registered\n", |
| 855 | req, req->r_tid); |
| 856 | return; |
| 857 | } |
| 858 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 859 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); |
| 860 | rb_erase(&req->r_node, &osdc->requests); |
| 861 | osdc->num_requests--; |
| 862 | |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 863 | if (req->r_osd) { |
| 864 | /* make sure the original request isn't in flight. */ |
Alex Elder | 6740a84 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 865 | ceph_msg_revoke(req->r_request); |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 866 | |
| 867 | list_del_init(&req->r_osd_item); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 868 | if (list_empty(&req->r_osd->o_requests) && |
| 869 | list_empty(&req->r_osd->o_linger_requests)) { |
| 870 | dout("moving osd to %p lru\n", req->r_osd); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 871 | __move_osd_to_lru(osdc, req->r_osd); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 872 | } |
Sage Weil | fbdb919 | 2011-03-29 12:11:06 -0700 | [diff] [blame] | 873 | if (list_empty(&req->r_linger_item)) |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 874 | req->r_osd = NULL; |
Sage Weil | 0ba6478 | 2009-10-08 16:57:16 -0700 | [diff] [blame] | 875 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 876 | |
| 877 | ceph_osdc_put_request(req); |
| 878 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 879 | list_del_init(&req->r_req_lru_item); |
| 880 | if (osdc->num_requests == 0) { |
| 881 | dout(" no requests, canceling timeout\n"); |
| 882 | __cancel_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | * Cancel a previously queued request message |
| 888 | */ |
| 889 | static void __cancel_request(struct ceph_osd_request *req) |
| 890 | { |
Sage Weil | 6bc1887 | 2010-09-27 10:18:52 -0700 | [diff] [blame] | 891 | if (req->r_sent && req->r_osd) { |
Alex Elder | 6740a84 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 892 | ceph_msg_revoke(req->r_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 893 | req->r_sent = 0; |
| 894 | } |
| 895 | } |
| 896 | |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 897 | static void __register_linger_request(struct ceph_osd_client *osdc, |
| 898 | struct ceph_osd_request *req) |
| 899 | { |
| 900 | dout("__register_linger_request %p\n", req); |
| 901 | list_add_tail(&req->r_linger_item, &osdc->req_linger); |
Sage Weil | 6194ea8 | 2012-07-30 16:19:28 -0700 | [diff] [blame] | 902 | if (req->r_osd) |
| 903 | list_add_tail(&req->r_linger_osd, |
| 904 | &req->r_osd->o_linger_requests); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | static void __unregister_linger_request(struct ceph_osd_client *osdc, |
| 908 | struct ceph_osd_request *req) |
| 909 | { |
| 910 | dout("__unregister_linger_request %p\n", req); |
| 911 | if (req->r_osd) { |
| 912 | list_del_init(&req->r_linger_item); |
| 913 | list_del_init(&req->r_linger_osd); |
| 914 | |
| 915 | if (list_empty(&req->r_osd->o_requests) && |
| 916 | list_empty(&req->r_osd->o_linger_requests)) { |
| 917 | dout("moving osd to %p lru\n", req->r_osd); |
| 918 | __move_osd_to_lru(osdc, req->r_osd); |
| 919 | } |
Sage Weil | fbdb919 | 2011-03-29 12:11:06 -0700 | [diff] [blame] | 920 | if (list_empty(&req->r_osd_item)) |
| 921 | req->r_osd = NULL; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
| 925 | void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc, |
| 926 | struct ceph_osd_request *req) |
| 927 | { |
| 928 | mutex_lock(&osdc->request_mutex); |
| 929 | if (req->r_linger) { |
| 930 | __unregister_linger_request(osdc, req); |
| 931 | ceph_osdc_put_request(req); |
| 932 | } |
| 933 | mutex_unlock(&osdc->request_mutex); |
| 934 | } |
| 935 | EXPORT_SYMBOL(ceph_osdc_unregister_linger_request); |
| 936 | |
| 937 | void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc, |
| 938 | struct ceph_osd_request *req) |
| 939 | { |
| 940 | if (!req->r_linger) { |
| 941 | dout("set_request_linger %p\n", req); |
| 942 | req->r_linger = 1; |
| 943 | /* |
| 944 | * caller is now responsible for calling |
| 945 | * unregister_linger_request |
| 946 | */ |
| 947 | ceph_osdc_get_request(req); |
| 948 | } |
| 949 | } |
| 950 | EXPORT_SYMBOL(ceph_osdc_set_request_linger); |
| 951 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 952 | /* |
| 953 | * Pick an osd (the first 'up' osd in the pg), allocate the osd struct |
| 954 | * (as needed), and set the request r_osd appropriately. If there is |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 955 | * no up osd, set r_osd to NULL. Move the request to the appropriate list |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 956 | * (unsent, homeless) or leave on in-flight lru. |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 957 | * |
| 958 | * Return 0 if unchanged, 1 if changed, or negative on error. |
| 959 | * |
| 960 | * Caller should hold map_sem for read and request_mutex. |
| 961 | */ |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 962 | static int __map_request(struct ceph_osd_client *osdc, |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 963 | struct ceph_osd_request *req, int force_resend) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 964 | { |
| 965 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 966 | struct ceph_pg pgid; |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 967 | int acting[CEPH_PG_MAX_SIZE]; |
| 968 | int o = -1, num = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 969 | int err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 970 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 971 | dout("map_request %p tid %lld\n", req, req->r_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 972 | err = ceph_calc_object_layout(&reqhead->layout, req->r_oid, |
| 973 | &req->r_file_layout, osdc->osdmap); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 974 | if (err) { |
| 975 | list_move(&req->r_req_lru_item, &osdc->req_notarget); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 976 | return err; |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 977 | } |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 978 | pgid = reqhead->layout.ol_pgid; |
Sage Weil | 7740a42 | 2010-01-08 15:58:25 -0800 | [diff] [blame] | 979 | req->r_pgid = pgid; |
| 980 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 981 | err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting); |
| 982 | if (err > 0) { |
| 983 | o = acting[0]; |
| 984 | num = err; |
| 985 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 986 | |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 987 | if ((!force_resend && |
| 988 | req->r_osd && req->r_osd->o_osd == o && |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 989 | req->r_sent >= req->r_osd->o_incarnation && |
| 990 | req->r_num_pg_osds == num && |
| 991 | memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 992 | (req->r_osd == NULL && o == -1)) |
| 993 | return 0; /* no change */ |
| 994 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 995 | dout("map_request tid %llu pgid %d.%x osd%d (was osd%d)\n", |
Sage Weil | 5104212 | 2009-11-04 11:39:12 -0800 | [diff] [blame] | 996 | req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 997 | req->r_osd ? req->r_osd->o_osd : -1); |
| 998 | |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 999 | /* record full pg acting set */ |
| 1000 | memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num); |
| 1001 | req->r_num_pg_osds = num; |
| 1002 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1003 | if (req->r_osd) { |
| 1004 | __cancel_request(req); |
| 1005 | list_del_init(&req->r_osd_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1006 | req->r_osd = NULL; |
| 1007 | } |
| 1008 | |
| 1009 | req->r_osd = __lookup_osd(osdc, o); |
| 1010 | if (!req->r_osd && o >= 0) { |
Sage Weil | c99eb1c | 2010-02-26 09:37:33 -0800 | [diff] [blame] | 1011 | err = -ENOMEM; |
Alex Elder | e10006f | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 1012 | req->r_osd = create_osd(osdc, o); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1013 | if (!req->r_osd) { |
| 1014 | list_move(&req->r_req_lru_item, &osdc->req_notarget); |
Sage Weil | c99eb1c | 2010-02-26 09:37:33 -0800 | [diff] [blame] | 1015 | goto out; |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1016 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1017 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1018 | dout("map_request osd %p is osd%d\n", req->r_osd, o); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1019 | __insert_osd(osdc, req->r_osd); |
| 1020 | |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 1021 | ceph_con_open(&req->r_osd->o_con, |
| 1022 | CEPH_ENTITY_TYPE_OSD, o, |
| 1023 | &osdc->osdmap->osd_addr[o]); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1026 | if (req->r_osd) { |
| 1027 | __remove_osd_from_lru(req->r_osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1028 | list_add(&req->r_osd_item, &req->r_osd->o_requests); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1029 | list_move(&req->r_req_lru_item, &osdc->req_unsent); |
| 1030 | } else { |
| 1031 | list_move(&req->r_req_lru_item, &osdc->req_notarget); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1032 | } |
Sage Weil | d85b705 | 2010-05-10 10:24:48 -0700 | [diff] [blame] | 1033 | err = 1; /* osd or pg changed */ |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1034 | |
| 1035 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1036 | return err; |
| 1037 | } |
| 1038 | |
| 1039 | /* |
| 1040 | * caller should hold map_sem (for read) and request_mutex |
| 1041 | */ |
Sage Weil | 56e925b | 2012-01-03 12:34:34 -0800 | [diff] [blame] | 1042 | static void __send_request(struct ceph_osd_client *osdc, |
| 1043 | struct ceph_osd_request *req) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1044 | { |
| 1045 | struct ceph_osd_request_head *reqhead; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1046 | |
| 1047 | dout("send_request %p tid %llu to osd%d flags %d\n", |
| 1048 | req, req->r_tid, req->r_osd->o_osd, req->r_flags); |
| 1049 | |
| 1050 | reqhead = req->r_request->front.iov_base; |
| 1051 | reqhead->osdmap_epoch = cpu_to_le32(osdc->osdmap->epoch); |
| 1052 | reqhead->flags |= cpu_to_le32(req->r_flags); /* e.g., RETRY */ |
| 1053 | reqhead->reassert_version = req->r_reassert_version; |
| 1054 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1055 | req->r_stamp = jiffies; |
Henry C Chang | 07a27e2 | 2010-08-22 21:34:27 -0700 | [diff] [blame] | 1056 | list_move_tail(&req->r_req_lru_item, &osdc->req_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1057 | |
| 1058 | ceph_msg_get(req->r_request); /* send consumes a ref */ |
| 1059 | ceph_con_send(&req->r_osd->o_con, req->r_request); |
| 1060 | req->r_sent = req->r_osd->o_incarnation; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /* |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1064 | * Send any requests in the queue (req_unsent). |
| 1065 | */ |
| 1066 | static void send_queued(struct ceph_osd_client *osdc) |
| 1067 | { |
| 1068 | struct ceph_osd_request *req, *tmp; |
| 1069 | |
| 1070 | dout("send_queued\n"); |
| 1071 | mutex_lock(&osdc->request_mutex); |
| 1072 | list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item) { |
| 1073 | __send_request(osdc, req); |
| 1074 | } |
| 1075 | mutex_unlock(&osdc->request_mutex); |
| 1076 | } |
| 1077 | |
| 1078 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1079 | * Timeout callback, called every N seconds when 1 or more osd |
| 1080 | * requests has been active for more than N seconds. When this |
| 1081 | * happens, we ping all OSDs with requests who have timed out to |
| 1082 | * ensure any communications channel reset is detected. Reset the |
| 1083 | * request timeouts another N seconds in the future as we go. |
| 1084 | * Reschedule the timeout event another N seconds in future (unless |
| 1085 | * there are no open requests). |
| 1086 | */ |
| 1087 | static void handle_timeout(struct work_struct *work) |
| 1088 | { |
| 1089 | struct ceph_osd_client *osdc = |
| 1090 | container_of(work, struct ceph_osd_client, timeout_work.work); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1091 | struct ceph_osd_request *req, *last_req = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1092 | struct ceph_osd *osd; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1093 | unsigned long timeout = osdc->client->options->osd_timeout * HZ; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1094 | unsigned long keepalive = |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1095 | osdc->client->options->osd_keepalive_timeout * HZ; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1096 | unsigned long last_stamp = 0; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1097 | struct list_head slow_osds; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1098 | dout("timeout\n"); |
| 1099 | down_read(&osdc->map_sem); |
| 1100 | |
| 1101 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 1102 | |
| 1103 | mutex_lock(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1104 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1105 | /* |
| 1106 | * reset osds that appear to be _really_ unresponsive. this |
| 1107 | * is a failsafe measure.. we really shouldn't be getting to |
| 1108 | * this point if the system is working properly. the monitors |
| 1109 | * should mark the osd as failed and we should find out about |
| 1110 | * it from an updated osd map. |
| 1111 | */ |
Sage Weil | f26e681 | 2010-04-21 11:09:38 -0700 | [diff] [blame] | 1112 | while (timeout && !list_empty(&osdc->req_lru)) { |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1113 | req = list_entry(osdc->req_lru.next, struct ceph_osd_request, |
| 1114 | r_req_lru_item); |
| 1115 | |
Sage Weil | 4cf9d54 | 2011-07-26 11:27:24 -0700 | [diff] [blame] | 1116 | /* hasn't been long enough since we sent it? */ |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1117 | if (time_before(jiffies, req->r_stamp + timeout)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1118 | break; |
| 1119 | |
Sage Weil | 4cf9d54 | 2011-07-26 11:27:24 -0700 | [diff] [blame] | 1120 | /* hasn't been long enough since it was acked? */ |
| 1121 | if (req->r_request->ack_stamp == 0 || |
| 1122 | time_before(jiffies, req->r_request->ack_stamp + timeout)) |
| 1123 | break; |
| 1124 | |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1125 | BUG_ON(req == last_req && req->r_stamp == last_stamp); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1126 | last_req = req; |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1127 | last_stamp = req->r_stamp; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1128 | |
| 1129 | osd = req->r_osd; |
| 1130 | BUG_ON(!osd); |
| 1131 | pr_warning(" tid %llu timed out on osd%d, will reset osd\n", |
| 1132 | req->r_tid, osd->o_osd); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1133 | __kick_osd_requests(osdc, osd); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /* |
| 1137 | * ping osds that are a bit slow. this ensures that if there |
| 1138 | * is a break in the TCP connection we will notice, and reopen |
| 1139 | * a connection with that osd (from the fault callback). |
| 1140 | */ |
| 1141 | INIT_LIST_HEAD(&slow_osds); |
| 1142 | list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) { |
Sage Weil | 3dd72fc | 2010-03-22 14:42:30 -0700 | [diff] [blame] | 1143 | if (time_before(jiffies, req->r_stamp + keepalive)) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1144 | break; |
| 1145 | |
| 1146 | osd = req->r_osd; |
| 1147 | BUG_ON(!osd); |
| 1148 | dout(" tid %llu is slow, will send keepalive on osd%d\n", |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1149 | req->r_tid, osd->o_osd); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1150 | list_move_tail(&osd->o_keepalive_item, &slow_osds); |
| 1151 | } |
| 1152 | while (!list_empty(&slow_osds)) { |
| 1153 | osd = list_entry(slow_osds.next, struct ceph_osd, |
| 1154 | o_keepalive_item); |
| 1155 | list_del_init(&osd->o_keepalive_item); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1156 | ceph_con_keepalive(&osd->o_con); |
| 1157 | } |
| 1158 | |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1159 | __schedule_osd_timeout(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1160 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1161 | send_queued(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1162 | up_read(&osdc->map_sem); |
| 1163 | } |
| 1164 | |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1165 | static void handle_osds_timeout(struct work_struct *work) |
| 1166 | { |
| 1167 | struct ceph_osd_client *osdc = |
| 1168 | container_of(work, struct ceph_osd_client, |
| 1169 | osds_timeout_work.work); |
| 1170 | unsigned long delay = |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1171 | osdc->client->options->osd_idle_ttl * HZ >> 2; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1172 | |
| 1173 | dout("osds timeout\n"); |
| 1174 | down_read(&osdc->map_sem); |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 1175 | remove_old_osds(osdc); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1176 | up_read(&osdc->map_sem); |
| 1177 | |
| 1178 | schedule_delayed_work(&osdc->osds_timeout_work, |
| 1179 | round_jiffies_relative(delay)); |
| 1180 | } |
| 1181 | |
Sage Weil | 2584547 | 2011-06-03 09:37:09 -0700 | [diff] [blame] | 1182 | static void complete_request(struct ceph_osd_request *req) |
| 1183 | { |
| 1184 | if (req->r_safe_callback) |
| 1185 | req->r_safe_callback(req, NULL); |
| 1186 | complete_all(&req->r_safe_completion); /* fsync waiter */ |
| 1187 | } |
| 1188 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1189 | /* |
| 1190 | * handle osd op reply. either call the callback if it is specified, |
| 1191 | * or do the completion to wake up the waiting thread. |
| 1192 | */ |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1193 | static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, |
| 1194 | struct ceph_connection *con) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1195 | { |
| 1196 | struct ceph_osd_reply_head *rhead = msg->front.iov_base; |
| 1197 | struct ceph_osd_request *req; |
| 1198 | u64 tid; |
| 1199 | int numops, object_len, flags; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1200 | s32 result; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1201 | |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 1202 | tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1203 | if (msg->front.iov_len < sizeof(*rhead)) |
| 1204 | goto bad; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1205 | numops = le32_to_cpu(rhead->num_ops); |
| 1206 | object_len = le32_to_cpu(rhead->object_len); |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1207 | result = le32_to_cpu(rhead->result); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1208 | if (msg->front.iov_len != sizeof(*rhead) + object_len + |
| 1209 | numops * sizeof(struct ceph_osd_op)) |
| 1210 | goto bad; |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1211 | dout("handle_reply %p tid %llu result %d\n", msg, tid, (int)result); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1212 | /* lookup */ |
| 1213 | mutex_lock(&osdc->request_mutex); |
| 1214 | req = __lookup_request(osdc, tid); |
| 1215 | if (req == NULL) { |
| 1216 | dout("handle_reply tid %llu dne\n", tid); |
| 1217 | mutex_unlock(&osdc->request_mutex); |
| 1218 | return; |
| 1219 | } |
| 1220 | ceph_osdc_get_request(req); |
| 1221 | flags = le32_to_cpu(rhead->flags); |
| 1222 | |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1223 | /* |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1224 | * if this connection filled our message, drop our reference now, to |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1225 | * avoid a (safe but slower) revoke later. |
| 1226 | */ |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1227 | if (req->r_con_filling_msg == con && req->r_reply == msg) { |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1228 | dout(" dropping con_filling_msg ref %p\n", con); |
Yehuda Sadeh | 0d59ab8 | 2010-01-13 17:03:23 -0800 | [diff] [blame] | 1229 | req->r_con_filling_msg = NULL; |
Sage Weil | 0d47766 | 2012-05-31 20:22:18 -0700 | [diff] [blame] | 1230 | con->ops->put(con); |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 1231 | } |
| 1232 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1233 | if (!req->r_got_reply) { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 1234 | unsigned int bytes; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1235 | |
| 1236 | req->r_result = le32_to_cpu(rhead->result); |
| 1237 | bytes = le32_to_cpu(msg->hdr.data_len); |
| 1238 | dout("handle_reply result %d bytes %d\n", req->r_result, |
| 1239 | bytes); |
| 1240 | if (req->r_result == 0) |
| 1241 | req->r_result = bytes; |
| 1242 | |
| 1243 | /* in case this is a write and we need to replay, */ |
| 1244 | req->r_reassert_version = rhead->reassert_version; |
| 1245 | |
| 1246 | req->r_got_reply = 1; |
| 1247 | } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) { |
| 1248 | dout("handle_reply tid %llu dup ack\n", tid); |
Sage Weil | 34b43a5 | 2009-12-01 12:23:54 -0800 | [diff] [blame] | 1249 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1250 | goto done; |
| 1251 | } |
| 1252 | |
| 1253 | dout("handle_reply tid %llu flags %d\n", tid, flags); |
| 1254 | |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1255 | if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK)) |
| 1256 | __register_linger_request(osdc, req); |
| 1257 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1258 | /* either this is a read, or we got the safe response */ |
Sage Weil | 0ceed5d | 2010-05-11 09:53:18 -0700 | [diff] [blame] | 1259 | if (result < 0 || |
| 1260 | (flags & CEPH_OSD_FLAG_ONDISK) || |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1261 | ((flags & CEPH_OSD_FLAG_WRITE) == 0)) |
| 1262 | __unregister_request(osdc, req); |
| 1263 | |
| 1264 | mutex_unlock(&osdc->request_mutex); |
| 1265 | |
| 1266 | if (req->r_callback) |
| 1267 | req->r_callback(req, msg); |
| 1268 | else |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1269 | complete_all(&req->r_completion); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1270 | |
Sage Weil | 2584547 | 2011-06-03 09:37:09 -0700 | [diff] [blame] | 1271 | if (flags & CEPH_OSD_FLAG_ONDISK) |
| 1272 | complete_request(req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1273 | |
| 1274 | done: |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1275 | dout("req=%p req->r_linger=%d\n", req, req->r_linger); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1276 | ceph_osdc_put_request(req); |
| 1277 | return; |
| 1278 | |
| 1279 | bad: |
| 1280 | pr_err("corrupt osd_op_reply got %d %d expected %d\n", |
| 1281 | (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len), |
| 1282 | (int)sizeof(*rhead)); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1283 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1286 | static void reset_changed_osds(struct ceph_osd_client *osdc) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1287 | { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1288 | struct rb_node *p, *n; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1289 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1290 | for (p = rb_first(&osdc->osds); p; p = n) { |
| 1291 | struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1292 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1293 | n = rb_next(p); |
| 1294 | if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) || |
| 1295 | memcmp(&osd->o_con.peer_addr, |
| 1296 | ceph_osd_addr(osdc->osdmap, |
| 1297 | osd->o_osd), |
| 1298 | sizeof(struct ceph_entity_addr)) != 0) |
| 1299 | __reset_osd(osdc, osd); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1300 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /* |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1304 | * Requeue requests whose mapping to an OSD has changed. If requests map to |
| 1305 | * no osd, request a new map. |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1306 | * |
| 1307 | * Caller should hold map_sem for read and request_mutex. |
| 1308 | */ |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1309 | static void kick_requests(struct ceph_osd_client *osdc, int force_resend) |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1310 | { |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1311 | struct ceph_osd_request *req, *nreq; |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1312 | struct rb_node *p; |
| 1313 | int needmap = 0; |
| 1314 | int err; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1315 | |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1316 | dout("kick_requests %s\n", force_resend ? " (force resend)" : ""); |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1317 | mutex_lock(&osdc->request_mutex); |
Sage Weil | 6194ea8 | 2012-07-30 16:19:28 -0700 | [diff] [blame] | 1318 | for (p = rb_first(&osdc->requests); p; ) { |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1319 | req = rb_entry(p, struct ceph_osd_request, r_node); |
Sage Weil | 6194ea8 | 2012-07-30 16:19:28 -0700 | [diff] [blame] | 1320 | p = rb_next(p); |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1321 | err = __map_request(osdc, req, force_resend); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1322 | if (err < 0) |
| 1323 | continue; /* error */ |
| 1324 | if (req->r_osd == NULL) { |
| 1325 | dout("%p tid %llu maps to no osd\n", req, req->r_tid); |
| 1326 | needmap++; /* request a newer map */ |
| 1327 | } else if (err > 0) { |
Sage Weil | 6194ea8 | 2012-07-30 16:19:28 -0700 | [diff] [blame] | 1328 | if (!req->r_linger) { |
| 1329 | dout("%p tid %llu requeued on osd%d\n", req, |
| 1330 | req->r_tid, |
| 1331 | req->r_osd ? req->r_osd->o_osd : -1); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1332 | req->r_flags |= CEPH_OSD_FLAG_RETRY; |
Sage Weil | 6194ea8 | 2012-07-30 16:19:28 -0700 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | if (req->r_linger && list_empty(&req->r_linger_item)) { |
| 1336 | /* |
| 1337 | * register as a linger so that we will |
| 1338 | * re-submit below and get a new tid |
| 1339 | */ |
| 1340 | dout("%p tid %llu restart on osd%d\n", |
| 1341 | req, req->r_tid, |
| 1342 | req->r_osd ? req->r_osd->o_osd : -1); |
| 1343 | __register_linger_request(osdc, req); |
| 1344 | __unregister_request(osdc, req); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1347 | |
| 1348 | list_for_each_entry_safe(req, nreq, &osdc->req_linger, |
| 1349 | r_linger_item) { |
| 1350 | dout("linger req=%p req->r_osd=%p\n", req, req->r_osd); |
| 1351 | |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1352 | err = __map_request(osdc, req, force_resend); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1353 | if (err == 0) |
| 1354 | continue; /* no change and no osd was specified */ |
| 1355 | if (err < 0) |
| 1356 | continue; /* hrm! */ |
| 1357 | if (req->r_osd == NULL) { |
| 1358 | dout("tid %llu maps to no valid osd\n", req->r_tid); |
| 1359 | needmap++; /* request a newer map */ |
| 1360 | continue; |
| 1361 | } |
| 1362 | |
| 1363 | dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid, |
| 1364 | req->r_osd ? req->r_osd->o_osd : -1); |
| 1365 | __unregister_linger_request(osdc, req); |
| 1366 | __register_request(osdc, req); |
| 1367 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1368 | mutex_unlock(&osdc->request_mutex); |
| 1369 | |
| 1370 | if (needmap) { |
| 1371 | dout("%d requests for down osds, need new map\n", needmap); |
| 1372 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 1373 | } |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1374 | } |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1375 | |
| 1376 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1377 | /* |
| 1378 | * Process updated osd map. |
| 1379 | * |
| 1380 | * The message contains any number of incremental and full maps, normally |
| 1381 | * indicating some sort of topology change in the cluster. Kick requests |
| 1382 | * off to different OSDs as needed. |
| 1383 | */ |
| 1384 | void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) |
| 1385 | { |
| 1386 | void *p, *end, *next; |
| 1387 | u32 nr_maps, maplen; |
| 1388 | u32 epoch; |
| 1389 | struct ceph_osdmap *newmap = NULL, *oldmap; |
| 1390 | int err; |
| 1391 | struct ceph_fsid fsid; |
| 1392 | |
| 1393 | dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0); |
| 1394 | p = msg->front.iov_base; |
| 1395 | end = p + msg->front.iov_len; |
| 1396 | |
| 1397 | /* verify fsid */ |
| 1398 | ceph_decode_need(&p, end, sizeof(fsid), bad); |
| 1399 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 1400 | if (ceph_check_fsid(osdc->client, &fsid) < 0) |
| 1401 | return; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1402 | |
| 1403 | down_write(&osdc->map_sem); |
| 1404 | |
| 1405 | /* incremental maps */ |
| 1406 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1407 | dout(" %d inc maps\n", nr_maps); |
| 1408 | while (nr_maps > 0) { |
| 1409 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1410 | epoch = ceph_decode_32(&p); |
| 1411 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1412 | ceph_decode_need(&p, end, maplen, bad); |
| 1413 | next = p + maplen; |
| 1414 | if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) { |
| 1415 | dout("applying incremental map %u len %d\n", |
| 1416 | epoch, maplen); |
| 1417 | newmap = osdmap_apply_incremental(&p, next, |
| 1418 | osdc->osdmap, |
Alex Elder | 15d9882 | 2012-05-26 23:26:43 -0500 | [diff] [blame] | 1419 | &osdc->client->msgr); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1420 | if (IS_ERR(newmap)) { |
| 1421 | err = PTR_ERR(newmap); |
| 1422 | goto bad; |
| 1423 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1424 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1425 | if (newmap != osdc->osdmap) { |
| 1426 | ceph_osdmap_destroy(osdc->osdmap); |
| 1427 | osdc->osdmap = newmap; |
| 1428 | } |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1429 | kick_requests(osdc, 0); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1430 | reset_changed_osds(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1431 | } else { |
| 1432 | dout("ignoring incremental map %u len %d\n", |
| 1433 | epoch, maplen); |
| 1434 | } |
| 1435 | p = next; |
| 1436 | nr_maps--; |
| 1437 | } |
| 1438 | if (newmap) |
| 1439 | goto done; |
| 1440 | |
| 1441 | /* full maps */ |
| 1442 | ceph_decode_32_safe(&p, end, nr_maps, bad); |
| 1443 | dout(" %d full maps\n", nr_maps); |
| 1444 | while (nr_maps) { |
| 1445 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 1446 | epoch = ceph_decode_32(&p); |
| 1447 | maplen = ceph_decode_32(&p); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1448 | ceph_decode_need(&p, end, maplen, bad); |
| 1449 | if (nr_maps > 1) { |
| 1450 | dout("skipping non-latest full map %u len %d\n", |
| 1451 | epoch, maplen); |
| 1452 | } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) { |
| 1453 | dout("skipping full map %u len %d, " |
| 1454 | "older than our %u\n", epoch, maplen, |
| 1455 | osdc->osdmap->epoch); |
| 1456 | } else { |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1457 | int skipped_map = 0; |
| 1458 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1459 | dout("taking full map %u len %d\n", epoch, maplen); |
| 1460 | newmap = osdmap_decode(&p, p+maplen); |
| 1461 | if (IS_ERR(newmap)) { |
| 1462 | err = PTR_ERR(newmap); |
| 1463 | goto bad; |
| 1464 | } |
Sage Weil | 30dc638 | 2009-12-21 14:49:37 -0800 | [diff] [blame] | 1465 | BUG_ON(!newmap); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1466 | oldmap = osdc->osdmap; |
| 1467 | osdc->osdmap = newmap; |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1468 | if (oldmap) { |
| 1469 | if (oldmap->epoch + 1 < newmap->epoch) |
| 1470 | skipped_map = 1; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1471 | ceph_osdmap_destroy(oldmap); |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1472 | } |
| 1473 | kick_requests(osdc, skipped_map); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1474 | } |
| 1475 | p += maplen; |
| 1476 | nr_maps--; |
| 1477 | } |
| 1478 | |
| 1479 | done: |
| 1480 | downgrade_write(&osdc->map_sem); |
| 1481 | ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch); |
Sage Weil | cd634fb | 2011-05-12 09:29:18 -0700 | [diff] [blame] | 1482 | |
| 1483 | /* |
| 1484 | * subscribe to subsequent osdmap updates if full to ensure |
| 1485 | * we find out when we are no longer full and stop returning |
| 1486 | * ENOSPC. |
| 1487 | */ |
| 1488 | if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL)) |
| 1489 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 1490 | |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1491 | send_queued(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1492 | up_read(&osdc->map_sem); |
Yehuda Sadeh | 03066f2 | 2010-07-27 13:11:08 -0700 | [diff] [blame] | 1493 | wake_up_all(&osdc->client->auth_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1494 | return; |
| 1495 | |
| 1496 | bad: |
| 1497 | pr_err("osdc handle_map corrupt msg\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 1498 | ceph_msg_dump(msg); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1499 | up_write(&osdc->map_sem); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1503 | /* |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1504 | * watch/notify callback event infrastructure |
| 1505 | * |
| 1506 | * These callbacks are used both for watch and notify operations. |
| 1507 | */ |
| 1508 | static void __release_event(struct kref *kref) |
| 1509 | { |
| 1510 | struct ceph_osd_event *event = |
| 1511 | container_of(kref, struct ceph_osd_event, kref); |
| 1512 | |
| 1513 | dout("__release_event %p\n", event); |
| 1514 | kfree(event); |
| 1515 | } |
| 1516 | |
| 1517 | static void get_event(struct ceph_osd_event *event) |
| 1518 | { |
| 1519 | kref_get(&event->kref); |
| 1520 | } |
| 1521 | |
| 1522 | void ceph_osdc_put_event(struct ceph_osd_event *event) |
| 1523 | { |
| 1524 | kref_put(&event->kref, __release_event); |
| 1525 | } |
| 1526 | EXPORT_SYMBOL(ceph_osdc_put_event); |
| 1527 | |
| 1528 | static void __insert_event(struct ceph_osd_client *osdc, |
| 1529 | struct ceph_osd_event *new) |
| 1530 | { |
| 1531 | struct rb_node **p = &osdc->event_tree.rb_node; |
| 1532 | struct rb_node *parent = NULL; |
| 1533 | struct ceph_osd_event *event = NULL; |
| 1534 | |
| 1535 | while (*p) { |
| 1536 | parent = *p; |
| 1537 | event = rb_entry(parent, struct ceph_osd_event, node); |
| 1538 | if (new->cookie < event->cookie) |
| 1539 | p = &(*p)->rb_left; |
| 1540 | else if (new->cookie > event->cookie) |
| 1541 | p = &(*p)->rb_right; |
| 1542 | else |
| 1543 | BUG(); |
| 1544 | } |
| 1545 | |
| 1546 | rb_link_node(&new->node, parent, p); |
| 1547 | rb_insert_color(&new->node, &osdc->event_tree); |
| 1548 | } |
| 1549 | |
| 1550 | static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc, |
| 1551 | u64 cookie) |
| 1552 | { |
| 1553 | struct rb_node **p = &osdc->event_tree.rb_node; |
| 1554 | struct rb_node *parent = NULL; |
| 1555 | struct ceph_osd_event *event = NULL; |
| 1556 | |
| 1557 | while (*p) { |
| 1558 | parent = *p; |
| 1559 | event = rb_entry(parent, struct ceph_osd_event, node); |
| 1560 | if (cookie < event->cookie) |
| 1561 | p = &(*p)->rb_left; |
| 1562 | else if (cookie > event->cookie) |
| 1563 | p = &(*p)->rb_right; |
| 1564 | else |
| 1565 | return event; |
| 1566 | } |
| 1567 | return NULL; |
| 1568 | } |
| 1569 | |
| 1570 | static void __remove_event(struct ceph_osd_event *event) |
| 1571 | { |
| 1572 | struct ceph_osd_client *osdc = event->osdc; |
| 1573 | |
| 1574 | if (!RB_EMPTY_NODE(&event->node)) { |
| 1575 | dout("__remove_event removed %p\n", event); |
| 1576 | rb_erase(&event->node, &osdc->event_tree); |
| 1577 | ceph_osdc_put_event(event); |
| 1578 | } else { |
| 1579 | dout("__remove_event didn't remove %p\n", event); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | int ceph_osdc_create_event(struct ceph_osd_client *osdc, |
| 1584 | void (*event_cb)(u64, u64, u8, void *), |
| 1585 | int one_shot, void *data, |
| 1586 | struct ceph_osd_event **pevent) |
| 1587 | { |
| 1588 | struct ceph_osd_event *event; |
| 1589 | |
| 1590 | event = kmalloc(sizeof(*event), GFP_NOIO); |
| 1591 | if (!event) |
| 1592 | return -ENOMEM; |
| 1593 | |
| 1594 | dout("create_event %p\n", event); |
| 1595 | event->cb = event_cb; |
| 1596 | event->one_shot = one_shot; |
| 1597 | event->data = data; |
| 1598 | event->osdc = osdc; |
| 1599 | INIT_LIST_HEAD(&event->osd_node); |
| 1600 | kref_init(&event->kref); /* one ref for us */ |
| 1601 | kref_get(&event->kref); /* one ref for the caller */ |
| 1602 | init_completion(&event->completion); |
| 1603 | |
| 1604 | spin_lock(&osdc->event_lock); |
| 1605 | event->cookie = ++osdc->event_count; |
| 1606 | __insert_event(osdc, event); |
| 1607 | spin_unlock(&osdc->event_lock); |
| 1608 | |
| 1609 | *pevent = event; |
| 1610 | return 0; |
| 1611 | } |
| 1612 | EXPORT_SYMBOL(ceph_osdc_create_event); |
| 1613 | |
| 1614 | void ceph_osdc_cancel_event(struct ceph_osd_event *event) |
| 1615 | { |
| 1616 | struct ceph_osd_client *osdc = event->osdc; |
| 1617 | |
| 1618 | dout("cancel_event %p\n", event); |
| 1619 | spin_lock(&osdc->event_lock); |
| 1620 | __remove_event(event); |
| 1621 | spin_unlock(&osdc->event_lock); |
| 1622 | ceph_osdc_put_event(event); /* caller's */ |
| 1623 | } |
| 1624 | EXPORT_SYMBOL(ceph_osdc_cancel_event); |
| 1625 | |
| 1626 | |
| 1627 | static void do_event_work(struct work_struct *work) |
| 1628 | { |
| 1629 | struct ceph_osd_event_work *event_work = |
| 1630 | container_of(work, struct ceph_osd_event_work, work); |
| 1631 | struct ceph_osd_event *event = event_work->event; |
| 1632 | u64 ver = event_work->ver; |
| 1633 | u64 notify_id = event_work->notify_id; |
| 1634 | u8 opcode = event_work->opcode; |
| 1635 | |
| 1636 | dout("do_event_work completing %p\n", event); |
| 1637 | event->cb(ver, notify_id, opcode, event->data); |
| 1638 | complete(&event->completion); |
| 1639 | dout("do_event_work completed %p\n", event); |
| 1640 | ceph_osdc_put_event(event); |
| 1641 | kfree(event_work); |
| 1642 | } |
| 1643 | |
| 1644 | |
| 1645 | /* |
| 1646 | * Process osd watch notifications |
| 1647 | */ |
| 1648 | void handle_watch_notify(struct ceph_osd_client *osdc, struct ceph_msg *msg) |
| 1649 | { |
| 1650 | void *p, *end; |
| 1651 | u8 proto_ver; |
| 1652 | u64 cookie, ver, notify_id; |
| 1653 | u8 opcode; |
| 1654 | struct ceph_osd_event *event; |
| 1655 | struct ceph_osd_event_work *event_work; |
| 1656 | |
| 1657 | p = msg->front.iov_base; |
| 1658 | end = p + msg->front.iov_len; |
| 1659 | |
| 1660 | ceph_decode_8_safe(&p, end, proto_ver, bad); |
| 1661 | ceph_decode_8_safe(&p, end, opcode, bad); |
| 1662 | ceph_decode_64_safe(&p, end, cookie, bad); |
| 1663 | ceph_decode_64_safe(&p, end, ver, bad); |
| 1664 | ceph_decode_64_safe(&p, end, notify_id, bad); |
| 1665 | |
| 1666 | spin_lock(&osdc->event_lock); |
| 1667 | event = __find_event(osdc, cookie); |
| 1668 | if (event) { |
| 1669 | get_event(event); |
| 1670 | if (event->one_shot) |
| 1671 | __remove_event(event); |
| 1672 | } |
| 1673 | spin_unlock(&osdc->event_lock); |
| 1674 | dout("handle_watch_notify cookie %lld ver %lld event %p\n", |
| 1675 | cookie, ver, event); |
| 1676 | if (event) { |
| 1677 | event_work = kmalloc(sizeof(*event_work), GFP_NOIO); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1678 | if (!event_work) { |
| 1679 | dout("ERROR: could not allocate event_work\n"); |
| 1680 | goto done_err; |
| 1681 | } |
Mariusz Kozlowski | 6b0ae40 | 2011-03-26 19:29:34 +0100 | [diff] [blame] | 1682 | INIT_WORK(&event_work->work, do_event_work); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1683 | event_work->event = event; |
| 1684 | event_work->ver = ver; |
| 1685 | event_work->notify_id = notify_id; |
| 1686 | event_work->opcode = opcode; |
| 1687 | if (!queue_work(osdc->notify_wq, &event_work->work)) { |
| 1688 | dout("WARNING: failed to queue notify event work\n"); |
| 1689 | goto done_err; |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | return; |
| 1694 | |
| 1695 | done_err: |
| 1696 | complete(&event->completion); |
| 1697 | ceph_osdc_put_event(event); |
| 1698 | return; |
| 1699 | |
| 1700 | bad: |
| 1701 | pr_err("osdc handle_watch_notify corrupt msg\n"); |
| 1702 | return; |
| 1703 | } |
| 1704 | |
| 1705 | int ceph_osdc_wait_event(struct ceph_osd_event *event, unsigned long timeout) |
| 1706 | { |
| 1707 | int err; |
| 1708 | |
| 1709 | dout("wait_event %p\n", event); |
| 1710 | err = wait_for_completion_interruptible_timeout(&event->completion, |
| 1711 | timeout * HZ); |
| 1712 | ceph_osdc_put_event(event); |
| 1713 | if (err > 0) |
| 1714 | err = 0; |
| 1715 | dout("wait_event %p returns %d\n", event, err); |
| 1716 | return err; |
| 1717 | } |
| 1718 | EXPORT_SYMBOL(ceph_osdc_wait_event); |
| 1719 | |
| 1720 | /* |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1721 | * Register request, send initial attempt. |
| 1722 | */ |
| 1723 | int ceph_osdc_start_request(struct ceph_osd_client *osdc, |
| 1724 | struct ceph_osd_request *req, |
| 1725 | bool nofail) |
| 1726 | { |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1727 | int rc = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1728 | |
| 1729 | req->r_request->pages = req->r_pages; |
| 1730 | req->r_request->nr_pages = req->r_num_pages; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 1731 | #ifdef CONFIG_BLOCK |
| 1732 | req->r_request->bio = req->r_bio; |
| 1733 | #endif |
| 1734 | req->r_request->trail = req->r_trail; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1735 | |
| 1736 | register_request(osdc, req); |
| 1737 | |
| 1738 | down_read(&osdc->map_sem); |
| 1739 | mutex_lock(&osdc->request_mutex); |
Sage Weil | c1ea882 | 2009-10-08 16:55:47 -0700 | [diff] [blame] | 1740 | /* |
| 1741 | * a racing kick_requests() may have sent the message for us |
| 1742 | * while we dropped request_mutex above, so only send now if |
| 1743 | * the request still han't been touched yet. |
| 1744 | */ |
| 1745 | if (req->r_sent == 0) { |
Sage Weil | 38d6453 | 2011-10-14 13:33:55 -0700 | [diff] [blame] | 1746 | rc = __map_request(osdc, req, 0); |
Sage Weil | 9d6fcb0 | 2011-05-12 15:48:16 -0700 | [diff] [blame] | 1747 | if (rc < 0) { |
| 1748 | if (nofail) { |
| 1749 | dout("osdc_start_request failed map, " |
| 1750 | " will retry %lld\n", req->r_tid); |
| 1751 | rc = 0; |
| 1752 | } |
Dan Carpenter | 234af26f | 2011-03-29 06:25:59 +0300 | [diff] [blame] | 1753 | goto out_unlock; |
Sage Weil | 9d6fcb0 | 2011-05-12 15:48:16 -0700 | [diff] [blame] | 1754 | } |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1755 | if (req->r_osd == NULL) { |
| 1756 | dout("send_request %p no up osds in pg\n", req); |
| 1757 | ceph_monc_request_next_osdmap(&osdc->client->monc); |
| 1758 | } else { |
Sage Weil | 56e925b | 2012-01-03 12:34:34 -0800 | [diff] [blame] | 1759 | __send_request(osdc, req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1760 | } |
Sage Weil | 56e925b | 2012-01-03 12:34:34 -0800 | [diff] [blame] | 1761 | rc = 0; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1762 | } |
Dan Carpenter | 234af26f | 2011-03-29 06:25:59 +0300 | [diff] [blame] | 1763 | |
| 1764 | out_unlock: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1765 | mutex_unlock(&osdc->request_mutex); |
| 1766 | up_read(&osdc->map_sem); |
| 1767 | return rc; |
| 1768 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1769 | EXPORT_SYMBOL(ceph_osdc_start_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1770 | |
| 1771 | /* |
| 1772 | * wait for a request to complete |
| 1773 | */ |
| 1774 | int ceph_osdc_wait_request(struct ceph_osd_client *osdc, |
| 1775 | struct ceph_osd_request *req) |
| 1776 | { |
| 1777 | int rc; |
| 1778 | |
| 1779 | rc = wait_for_completion_interruptible(&req->r_completion); |
| 1780 | if (rc < 0) { |
| 1781 | mutex_lock(&osdc->request_mutex); |
| 1782 | __cancel_request(req); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1783 | __unregister_request(osdc, req); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1784 | mutex_unlock(&osdc->request_mutex); |
Sage Weil | 2584547 | 2011-06-03 09:37:09 -0700 | [diff] [blame] | 1785 | complete_request(req); |
Sage Weil | 529cfcc | 2009-12-22 10:29:39 -0800 | [diff] [blame] | 1786 | dout("wait_request tid %llu canceled/timed out\n", req->r_tid); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1787 | return rc; |
| 1788 | } |
| 1789 | |
| 1790 | dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result); |
| 1791 | return req->r_result; |
| 1792 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1793 | EXPORT_SYMBOL(ceph_osdc_wait_request); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1794 | |
| 1795 | /* |
| 1796 | * sync - wait for all in-flight requests to flush. avoid starvation. |
| 1797 | */ |
| 1798 | void ceph_osdc_sync(struct ceph_osd_client *osdc) |
| 1799 | { |
| 1800 | struct ceph_osd_request *req; |
| 1801 | u64 last_tid, next_tid = 0; |
| 1802 | |
| 1803 | mutex_lock(&osdc->request_mutex); |
| 1804 | last_tid = osdc->last_tid; |
| 1805 | while (1) { |
| 1806 | req = __lookup_request_ge(osdc, next_tid); |
| 1807 | if (!req) |
| 1808 | break; |
| 1809 | if (req->r_tid > last_tid) |
| 1810 | break; |
| 1811 | |
| 1812 | next_tid = req->r_tid + 1; |
| 1813 | if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0) |
| 1814 | continue; |
| 1815 | |
| 1816 | ceph_osdc_get_request(req); |
| 1817 | mutex_unlock(&osdc->request_mutex); |
| 1818 | dout("sync waiting on tid %llu (last is %llu)\n", |
| 1819 | req->r_tid, last_tid); |
| 1820 | wait_for_completion(&req->r_safe_completion); |
| 1821 | mutex_lock(&osdc->request_mutex); |
| 1822 | ceph_osdc_put_request(req); |
| 1823 | } |
| 1824 | mutex_unlock(&osdc->request_mutex); |
| 1825 | dout("sync done (thru tid %llu)\n", last_tid); |
| 1826 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1827 | EXPORT_SYMBOL(ceph_osdc_sync); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1828 | |
| 1829 | /* |
| 1830 | * init, shutdown |
| 1831 | */ |
| 1832 | int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client) |
| 1833 | { |
| 1834 | int err; |
| 1835 | |
| 1836 | dout("init\n"); |
| 1837 | osdc->client = client; |
| 1838 | osdc->osdmap = NULL; |
| 1839 | init_rwsem(&osdc->map_sem); |
| 1840 | init_completion(&osdc->map_waiters); |
| 1841 | osdc->last_requested_map = 0; |
| 1842 | mutex_init(&osdc->request_mutex); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1843 | osdc->last_tid = 0; |
| 1844 | osdc->osds = RB_ROOT; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1845 | INIT_LIST_HEAD(&osdc->osd_lru); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1846 | osdc->requests = RB_ROOT; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 1847 | INIT_LIST_HEAD(&osdc->req_lru); |
Sage Weil | 6f6c700 | 2011-01-17 20:34:08 -0800 | [diff] [blame] | 1848 | INIT_LIST_HEAD(&osdc->req_unsent); |
| 1849 | INIT_LIST_HEAD(&osdc->req_notarget); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1850 | INIT_LIST_HEAD(&osdc->req_linger); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1851 | osdc->num_requests = 0; |
| 1852 | INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1853 | INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout); |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1854 | spin_lock_init(&osdc->event_lock); |
| 1855 | osdc->event_tree = RB_ROOT; |
| 1856 | osdc->event_count = 0; |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1857 | |
| 1858 | schedule_delayed_work(&osdc->osds_timeout_work, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1859 | round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ)); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1860 | |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1861 | err = -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1862 | osdc->req_mempool = mempool_create_kmalloc_pool(10, |
| 1863 | sizeof(struct ceph_osd_request)); |
| 1864 | if (!osdc->req_mempool) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1865 | goto out; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1866 | |
Sage Weil | d50b409 | 2012-07-09 14:22:34 -0700 | [diff] [blame] | 1867 | err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP, |
| 1868 | OSD_OP_FRONT_LEN, 10, true, |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1869 | "osd_op"); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1870 | if (err < 0) |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1871 | goto out_mempool; |
Sage Weil | d50b409 | 2012-07-09 14:22:34 -0700 | [diff] [blame] | 1872 | err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY, |
Sage Weil | 4f48280 | 2010-04-24 09:56:35 -0700 | [diff] [blame] | 1873 | OSD_OPREPLY_FRONT_LEN, 10, true, |
| 1874 | "osd_op_reply"); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1875 | if (err < 0) |
| 1876 | goto out_msgpool; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1877 | |
| 1878 | osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify"); |
| 1879 | if (IS_ERR(osdc->notify_wq)) { |
| 1880 | err = PTR_ERR(osdc->notify_wq); |
| 1881 | osdc->notify_wq = NULL; |
| 1882 | goto out_msgpool; |
| 1883 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1884 | return 0; |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1885 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1886 | out_msgpool: |
| 1887 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 1888 | out_mempool: |
| 1889 | mempool_destroy(osdc->req_mempool); |
| 1890 | out: |
| 1891 | return err; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1892 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1893 | EXPORT_SYMBOL(ceph_osdc_init); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1894 | |
| 1895 | void ceph_osdc_stop(struct ceph_osd_client *osdc) |
| 1896 | { |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 1897 | flush_workqueue(osdc->notify_wq); |
| 1898 | destroy_workqueue(osdc->notify_wq); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1899 | cancel_delayed_work_sync(&osdc->timeout_work); |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 1900 | cancel_delayed_work_sync(&osdc->osds_timeout_work); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1901 | if (osdc->osdmap) { |
| 1902 | ceph_osdmap_destroy(osdc->osdmap); |
| 1903 | osdc->osdmap = NULL; |
| 1904 | } |
Sage Weil | aca420b | 2011-08-31 14:45:53 -0700 | [diff] [blame] | 1905 | remove_all_osds(osdc); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1906 | mempool_destroy(osdc->req_mempool); |
| 1907 | ceph_msgpool_destroy(&osdc->msgpool_op); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 1908 | ceph_msgpool_destroy(&osdc->msgpool_op_reply); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1909 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1910 | EXPORT_SYMBOL(ceph_osdc_stop); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1911 | |
| 1912 | /* |
| 1913 | * Read some contiguous pages. If we cross a stripe boundary, shorten |
| 1914 | * *plen. Return number of bytes read, or error. |
| 1915 | */ |
| 1916 | int ceph_osdc_readpages(struct ceph_osd_client *osdc, |
| 1917 | struct ceph_vino vino, struct ceph_file_layout *layout, |
| 1918 | u64 off, u64 *plen, |
| 1919 | u32 truncate_seq, u64 truncate_size, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1920 | struct page **pages, int num_pages, int page_align) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1921 | { |
| 1922 | struct ceph_osd_request *req; |
| 1923 | int rc = 0; |
| 1924 | |
| 1925 | dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino, |
| 1926 | vino.snap, off, *plen); |
| 1927 | req = ceph_osdc_new_request(osdc, layout, vino, off, plen, |
| 1928 | CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ, |
| 1929 | NULL, 0, truncate_seq, truncate_size, NULL, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1930 | false, 1, page_align); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1931 | if (!req) |
| 1932 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1933 | |
| 1934 | /* it may be a short read due to an object boundary */ |
| 1935 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1936 | |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1937 | dout("readpages final extent is %llu~%llu (%d pages align %d)\n", |
| 1938 | off, *plen, req->r_num_pages, page_align); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1939 | |
| 1940 | rc = ceph_osdc_start_request(osdc, req, false); |
| 1941 | if (!rc) |
| 1942 | rc = ceph_osdc_wait_request(osdc, req); |
| 1943 | |
| 1944 | ceph_osdc_put_request(req); |
| 1945 | dout("readpages result %d\n", rc); |
| 1946 | return rc; |
| 1947 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1948 | EXPORT_SYMBOL(ceph_osdc_readpages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1949 | |
| 1950 | /* |
| 1951 | * do a synchronous write on N pages |
| 1952 | */ |
| 1953 | int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino, |
| 1954 | struct ceph_file_layout *layout, |
| 1955 | struct ceph_snap_context *snapc, |
| 1956 | u64 off, u64 len, |
| 1957 | u32 truncate_seq, u64 truncate_size, |
| 1958 | struct timespec *mtime, |
| 1959 | struct page **pages, int num_pages, |
| 1960 | int flags, int do_sync, bool nofail) |
| 1961 | { |
| 1962 | struct ceph_osd_request *req; |
| 1963 | int rc = 0; |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1964 | int page_align = off & ~PAGE_MASK; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1965 | |
| 1966 | BUG_ON(vino.snap != CEPH_NOSNAP); |
| 1967 | req = ceph_osdc_new_request(osdc, layout, vino, off, &len, |
| 1968 | CEPH_OSD_OP_WRITE, |
| 1969 | flags | CEPH_OSD_FLAG_ONDISK | |
| 1970 | CEPH_OSD_FLAG_WRITE, |
| 1971 | snapc, do_sync, |
| 1972 | truncate_seq, truncate_size, mtime, |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 1973 | nofail, 1, page_align); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1974 | if (!req) |
| 1975 | return -ENOMEM; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1976 | |
| 1977 | /* it may be a short write due to an object boundary */ |
| 1978 | req->r_pages = pages; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1979 | dout("writepages %llu~%llu (%d pages)\n", off, len, |
| 1980 | req->r_num_pages); |
| 1981 | |
| 1982 | rc = ceph_osdc_start_request(osdc, req, nofail); |
| 1983 | if (!rc) |
| 1984 | rc = ceph_osdc_wait_request(osdc, req); |
| 1985 | |
| 1986 | ceph_osdc_put_request(req); |
| 1987 | if (rc == 0) |
| 1988 | rc = len; |
| 1989 | dout("writepages result %d\n", rc); |
| 1990 | return rc; |
| 1991 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1992 | EXPORT_SYMBOL(ceph_osdc_writepages); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 1993 | |
| 1994 | /* |
| 1995 | * handle incoming message |
| 1996 | */ |
| 1997 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 1998 | { |
| 1999 | struct ceph_osd *osd = con->private; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 2000 | struct ceph_osd_client *osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2001 | int type = le16_to_cpu(msg->hdr.type); |
| 2002 | |
| 2003 | if (!osd) |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 2004 | goto out; |
Julia Lawall | 32c895e | 2009-11-21 16:53:16 +0100 | [diff] [blame] | 2005 | osdc = osd->o_osdc; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2006 | |
| 2007 | switch (type) { |
| 2008 | case CEPH_MSG_OSD_MAP: |
| 2009 | ceph_osdc_handle_map(osdc, msg); |
| 2010 | break; |
| 2011 | case CEPH_MSG_OSD_OPREPLY: |
Sage Weil | 350b1c3 | 2009-12-22 10:45:45 -0800 | [diff] [blame] | 2012 | handle_reply(osdc, msg, con); |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2013 | break; |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 2014 | case CEPH_MSG_WATCH_NOTIFY: |
| 2015 | handle_watch_notify(osdc, msg); |
| 2016 | break; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2017 | |
| 2018 | default: |
| 2019 | pr_err("received unknown message type %d %s\n", type, |
| 2020 | ceph_msg_type_name(type)); |
| 2021 | } |
Sage Weil | 4a32f93 | 2010-06-13 10:27:53 -0700 | [diff] [blame] | 2022 | out: |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2023 | ceph_msg_put(msg); |
| 2024 | } |
| 2025 | |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2026 | /* |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 2027 | * lookup and return message for incoming reply. set up reply message |
| 2028 | * pages. |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2029 | */ |
| 2030 | static struct ceph_msg *get_reply(struct ceph_connection *con, |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 2031 | struct ceph_msg_header *hdr, |
| 2032 | int *skip) |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2033 | { |
| 2034 | struct ceph_osd *osd = con->private; |
| 2035 | struct ceph_osd_client *osdc = osd->o_osdc; |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 2036 | struct ceph_msg *m; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2037 | struct ceph_osd_request *req; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2038 | int front = le32_to_cpu(hdr->front_len); |
| 2039 | int data_len = le32_to_cpu(hdr->data_len); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2040 | u64 tid; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2041 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2042 | tid = le64_to_cpu(hdr->tid); |
| 2043 | mutex_lock(&osdc->request_mutex); |
| 2044 | req = __lookup_request(osdc, tid); |
| 2045 | if (!req) { |
| 2046 | *skip = 1; |
| 2047 | m = NULL; |
Sage Weil | 756a16a | 2012-07-30 16:26:13 -0700 | [diff] [blame] | 2048 | dout("get_reply unknown tid %llu from osd%d\n", tid, |
| 2049 | osd->o_osd); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2050 | goto out; |
| 2051 | } |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 2052 | |
| 2053 | if (req->r_con_filling_msg) { |
Alex Elder | 8921d11 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 2054 | dout("%s revoking msg %p from old con %p\n", __func__, |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 2055 | req->r_reply, req->r_con_filling_msg); |
Alex Elder | 8921d11 | 2012-06-01 14:56:43 -0500 | [diff] [blame] | 2056 | ceph_msg_revoke_incoming(req->r_reply); |
Sage Weil | 0d47766 | 2012-05-31 20:22:18 -0700 | [diff] [blame] | 2057 | req->r_con_filling_msg->ops->put(req->r_con_filling_msg); |
Sage Weil | 6f46cb2 | 2010-03-24 21:30:19 -0700 | [diff] [blame] | 2058 | req->r_con_filling_msg = NULL; |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2059 | } |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 2060 | |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 2061 | if (front > req->r_reply->front.iov_len) { |
| 2062 | pr_warning("get_reply front %d > preallocated %d\n", |
| 2063 | front, (int)req->r_reply->front.iov_len); |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 2064 | m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS, false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 2065 | if (!m) |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 2066 | goto out; |
| 2067 | ceph_msg_put(req->r_reply); |
| 2068 | req->r_reply = m; |
| 2069 | } |
| 2070 | m = ceph_msg_get(req->r_reply); |
| 2071 | |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2072 | if (data_len > 0) { |
Sage Weil | b7495fc | 2010-11-09 12:43:12 -0800 | [diff] [blame] | 2073 | int want = calc_pages_for(req->r_page_alignment, data_len); |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 2074 | |
| 2075 | if (unlikely(req->r_num_pages < want)) { |
Sage Weil | 9bb0ce2 | 2011-06-13 16:20:18 -0700 | [diff] [blame] | 2076 | pr_warning("tid %lld reply has %d bytes %d pages, we" |
| 2077 | " had only %d pages ready\n", tid, data_len, |
| 2078 | want, req->r_num_pages); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2079 | *skip = 1; |
| 2080 | ceph_msg_put(m); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 2081 | m = NULL; |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 2082 | goto out; |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2083 | } |
Sage Weil | 21b667f | 2010-03-04 10:22:59 -0800 | [diff] [blame] | 2084 | m->pages = req->r_pages; |
| 2085 | m->nr_pages = req->r_num_pages; |
Sage Weil | c5c6b19 | 2010-11-09 12:40:00 -0800 | [diff] [blame] | 2086 | m->page_alignment = req->r_page_alignment; |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 2087 | #ifdef CONFIG_BLOCK |
| 2088 | m->bio = req->r_bio; |
| 2089 | #endif |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2090 | } |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2091 | *skip = 0; |
Sage Weil | 0d47766 | 2012-05-31 20:22:18 -0700 | [diff] [blame] | 2092 | req->r_con_filling_msg = con->ops->get(con); |
Sage Weil | c16e786 | 2010-03-01 13:02:00 -0800 | [diff] [blame] | 2093 | dout("get_reply tid %lld %p\n", tid, m); |
Yehuda Sadeh | 0547a9b | 2010-01-11 14:47:13 -0800 | [diff] [blame] | 2094 | |
| 2095 | out: |
| 2096 | mutex_unlock(&osdc->request_mutex); |
Yehuda Sadeh | 2450418 | 2010-01-08 13:58:34 -0800 | [diff] [blame] | 2097 | return m; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2098 | |
| 2099 | } |
| 2100 | |
| 2101 | static struct ceph_msg *alloc_msg(struct ceph_connection *con, |
| 2102 | struct ceph_msg_header *hdr, |
| 2103 | int *skip) |
| 2104 | { |
| 2105 | struct ceph_osd *osd = con->private; |
| 2106 | int type = le16_to_cpu(hdr->type); |
| 2107 | int front = le32_to_cpu(hdr->front_len); |
| 2108 | |
Alex Elder | 1c20f2d | 2012-06-04 14:43:32 -0500 | [diff] [blame] | 2109 | *skip = 0; |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2110 | switch (type) { |
| 2111 | case CEPH_MSG_OSD_MAP: |
Yehuda Sadeh | a40c4f1 | 2011-03-21 15:07:16 -0700 | [diff] [blame] | 2112 | case CEPH_MSG_WATCH_NOTIFY: |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 2113 | return ceph_msg_new(type, front, GFP_NOFS, false); |
Sage Weil | 5b3a4db | 2010-02-19 21:43:23 -0800 | [diff] [blame] | 2114 | case CEPH_MSG_OSD_OPREPLY: |
| 2115 | return get_reply(con, hdr, skip); |
| 2116 | default: |
| 2117 | pr_info("alloc_msg unexpected msg type %d from osd%d\n", type, |
| 2118 | osd->o_osd); |
| 2119 | *skip = 1; |
| 2120 | return NULL; |
| 2121 | } |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /* |
| 2125 | * Wrappers to refcount containing ceph_osd struct |
| 2126 | */ |
| 2127 | static struct ceph_connection *get_osd_con(struct ceph_connection *con) |
| 2128 | { |
| 2129 | struct ceph_osd *osd = con->private; |
| 2130 | if (get_osd(osd)) |
| 2131 | return con; |
| 2132 | return NULL; |
| 2133 | } |
| 2134 | |
| 2135 | static void put_osd_con(struct ceph_connection *con) |
| 2136 | { |
| 2137 | struct ceph_osd *osd = con->private; |
| 2138 | put_osd(osd); |
| 2139 | } |
| 2140 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2141 | /* |
| 2142 | * authentication |
| 2143 | */ |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2144 | /* |
| 2145 | * Note: returned pointer is the address of a structure that's |
| 2146 | * managed separately. Caller must *not* attempt to free it. |
| 2147 | */ |
| 2148 | static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con, |
Alex Elder | 8f43fb5 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2149 | int *proto, int force_new) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2150 | { |
| 2151 | struct ceph_osd *o = con->private; |
| 2152 | struct ceph_osd_client *osdc = o->o_osdc; |
| 2153 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2154 | struct ceph_auth_handshake *auth = &o->o_auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2155 | |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2156 | if (force_new && auth->authorizer) { |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2157 | if (ac->ops && ac->ops->destroy_authorizer) |
| 2158 | ac->ops->destroy_authorizer(ac, auth->authorizer); |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2159 | auth->authorizer = NULL; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2160 | } |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2161 | if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) { |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2162 | int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_OSD, |
| 2163 | auth); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2164 | if (ret) |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2165 | return ERR_PTR(ret); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2166 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2167 | *proto = ac->protocol; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2168 | |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2169 | return auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | static int verify_authorizer_reply(struct ceph_connection *con, int len) |
| 2174 | { |
| 2175 | struct ceph_osd *o = con->private; |
| 2176 | struct ceph_osd_client *osdc = o->o_osdc; |
| 2177 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 2178 | |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2179 | /* |
| 2180 | * XXX If ac->ops or ac->ops->verify_authorizer_reply is null, |
| 2181 | * XXX which do we do: succeed or fail? |
| 2182 | */ |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 2183 | return ac->ops->verify_authorizer_reply(ac, o->o_auth.authorizer, len); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2184 | } |
| 2185 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 2186 | static int invalidate_authorizer(struct ceph_connection *con) |
| 2187 | { |
| 2188 | struct ceph_osd *o = con->private; |
| 2189 | struct ceph_osd_client *osdc = o->o_osdc; |
| 2190 | struct ceph_auth_client *ac = osdc->client->monc.auth; |
| 2191 | |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 2192 | if (ac->ops && ac->ops->invalidate_authorizer) |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 2193 | ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD); |
| 2194 | |
| 2195 | return ceph_monc_validate_auth(&osdc->client->monc); |
| 2196 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2197 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 2198 | static const struct ceph_connection_operations osd_con_ops = { |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2199 | .get = get_osd_con, |
| 2200 | .put = put_osd_con, |
| 2201 | .dispatch = dispatch, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 2202 | .get_authorizer = get_authorizer, |
| 2203 | .verify_authorizer_reply = verify_authorizer_reply, |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 2204 | .invalidate_authorizer = invalidate_authorizer, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2205 | .alloc_msg = alloc_msg, |
Sage Weil | 81b024e | 2009-10-09 10:29:18 -0700 | [diff] [blame] | 2206 | .fault = osd_reset, |
Sage Weil | f24e998 | 2009-10-06 11:31:10 -0700 | [diff] [blame] | 2207 | }; |