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