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