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