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