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