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