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