Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2001 Clemson University and The University of Chicago |
| 3 | * (C) 2011 Omnibond Systems |
| 4 | * |
| 5 | * Changes by Acxiom Corporation to implement generic service_operation() |
| 6 | * function, Copyright Acxiom Corporation, 2005. |
| 7 | * |
| 8 | * See COPYING in top-level directory. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * In-kernel waitqueue operations. |
| 13 | */ |
| 14 | |
| 15 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 16 | #include "orangefs-kernel.h" |
| 17 | #include "orangefs-bufmap.h" |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 18 | |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 19 | static int wait_for_matching_downcall(struct orangefs_kernel_op_s *, long, bool); |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 20 | static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *); |
Al Viro | ade3d78 | 2016-01-21 22:58:58 -0500 | [diff] [blame] | 21 | |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 22 | /* |
| 23 | * What we do in this function is to walk the list of operations that are |
| 24 | * present in the request queue and mark them as purged. |
| 25 | * NOTE: This is called from the device close after client-core has |
| 26 | * guaranteed that no new operations could appear on the list since the |
| 27 | * client-core is anyway going to exit. |
| 28 | */ |
| 29 | void purge_waiting_ops(void) |
| 30 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 31 | struct orangefs_kernel_op_s *op; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 32 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 33 | spin_lock(&orangefs_request_list_lock); |
| 34 | list_for_each_entry(op, &orangefs_request_list, list) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 35 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 36 | "pvfs2-client-core: purging op tag %llu %s\n", |
| 37 | llu(op->tag), |
| 38 | get_opname_string(op)); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 39 | set_op_state_purged(op); |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 40 | gossip_debug(GOSSIP_DEV_DEBUG, |
| 41 | "%s: op:%s: op_state:%d: process:%s:\n", |
| 42 | __func__, |
| 43 | get_opname_string(op), |
| 44 | op->op_state, |
| 45 | current->comm); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 46 | } |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 47 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 51 | * submits a ORANGEFS operation and waits for it to complete |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 52 | * |
| 53 | * Note op->downcall.status will contain the status of the operation (in |
| 54 | * errno format), whether provided by pvfs2-client or a result of failure to |
| 55 | * service the operation. If the caller wishes to distinguish, then |
| 56 | * op->state can be checked to see if it was serviced or not. |
| 57 | * |
| 58 | * Returns contents of op->downcall.status for convenience |
| 59 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 60 | int service_operation(struct orangefs_kernel_op_s *op, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 61 | const char *op_name, |
| 62 | int flags) |
| 63 | { |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 64 | long timeout = MAX_SCHEDULE_TIMEOUT; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 65 | int ret = 0; |
| 66 | |
Mike Marshall | ce6c414 | 2015-12-14 14:54:46 -0500 | [diff] [blame] | 67 | DEFINE_WAIT(wait_entry); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 68 | |
| 69 | op->upcall.tgid = current->tgid; |
| 70 | op->upcall.pid = current->pid; |
| 71 | |
| 72 | retry_servicing: |
| 73 | op->downcall.status = 0; |
| 74 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 75 | "%s: %s op:%p: process:%s: pid:%d:\n", |
| 76 | __func__, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 77 | op_name, |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 78 | op, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 79 | current->comm, |
| 80 | current->pid); |
| 81 | |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 82 | /* |
| 83 | * If ORANGEFS_OP_NO_MUTEX was set in flags, we need to avoid |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 84 | * acquiring the request_mutex because we're servicing a |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 85 | * high priority remount operation and the request_mutex is |
| 86 | * already taken. |
| 87 | */ |
| 88 | if (!(flags & ORANGEFS_OP_NO_MUTEX)) { |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 89 | if (flags & ORANGEFS_OP_INTERRUPTIBLE) |
Martin Brandenburg | 1d50361 | 2016-08-16 11:38:14 -0400 | [diff] [blame] | 90 | ret = mutex_lock_interruptible(&orangefs_request_mutex); |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 91 | else |
Martin Brandenburg | 1d50361 | 2016-08-16 11:38:14 -0400 | [diff] [blame] | 92 | ret = mutex_lock_killable(&orangefs_request_mutex); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 93 | /* |
| 94 | * check to see if we were interrupted while waiting for |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 95 | * mutex |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 96 | */ |
| 97 | if (ret < 0) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 98 | op->downcall.status = ret; |
| 99 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 100 | "%s: service_operation interrupted.\n", |
| 101 | __func__); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 102 | return ret; |
| 103 | } |
| 104 | } |
| 105 | |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 106 | /* queue up the operation */ |
| 107 | spin_lock(&orangefs_request_list_lock); |
| 108 | spin_lock(&op->lock); |
| 109 | set_op_state_waiting(op); |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 110 | gossip_debug(GOSSIP_DEV_DEBUG, |
| 111 | "%s: op:%s: op_state:%d: process:%s:\n", |
| 112 | __func__, |
| 113 | get_opname_string(op), |
| 114 | op->op_state, |
| 115 | current->comm); |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 116 | /* add high priority remount op to the front of the line. */ |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 117 | if (flags & ORANGEFS_OP_PRIORITY) |
| 118 | list_add(&op->list, &orangefs_request_list); |
| 119 | else |
| 120 | list_add_tail(&op->list, &orangefs_request_list); |
| 121 | spin_unlock(&op->lock); |
| 122 | wake_up_interruptible(&orangefs_request_list_waitq); |
| 123 | if (!__is_daemon_in_service()) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 124 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 125 | "%s:client core is NOT in service.\n", |
| 126 | __func__); |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 127 | timeout = op_timeout_secs * HZ; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 128 | } |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 129 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 130 | |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 131 | if (!(flags & ORANGEFS_OP_NO_MUTEX)) |
Martin Brandenburg | 1d50361 | 2016-08-16 11:38:14 -0400 | [diff] [blame] | 132 | mutex_unlock(&orangefs_request_mutex); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 133 | |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 134 | ret = wait_for_matching_downcall(op, timeout, |
| 135 | flags & ORANGEFS_OP_INTERRUPTIBLE); |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 136 | |
| 137 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 138 | "%s: wait_for_matching_downcall returned %d for %p\n", |
| 139 | __func__, |
| 140 | ret, |
| 141 | op); |
| 142 | |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 143 | /* got matching downcall; make sure status is in errno format */ |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 144 | if (!ret) { |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 145 | spin_unlock(&op->lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 146 | op->downcall.status = |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 147 | orangefs_normalize_to_errno(op->downcall.status); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 148 | ret = op->downcall.status; |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 149 | goto out; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 152 | /* failed to get matching downcall */ |
| 153 | if (ret == -ETIMEDOUT) { |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 154 | gossip_err("%s: %s -- wait timed out; aborting attempt.\n", |
| 155 | __func__, |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 156 | op_name); |
| 157 | } |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 158 | |
| 159 | /* |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 160 | * remove a waiting op from the request list or |
| 161 | * remove an in-progress op from the in-progress list. |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 162 | */ |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 163 | orangefs_clean_up_interrupted_operation(op); |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 164 | |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 165 | op->downcall.status = ret; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 166 | /* retry if operation has not been serviced and if requested */ |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 167 | if (ret == -EAGAIN) { |
| 168 | op->attempts++; |
| 169 | timeout = op_timeout_secs * HZ; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 170 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 171 | "orangefs: tag %llu (%s)" |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 172 | " -- operation to be retried (%d attempt)\n", |
| 173 | llu(op->tag), |
| 174 | op_name, |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 175 | op->attempts); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 176 | |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 177 | /* |
| 178 | * io ops (ops that use the shared memory buffer) have |
| 179 | * to be returned to their caller for a retry. Other ops |
| 180 | * can just be recycled here. |
| 181 | */ |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 182 | if (!op->uses_shared_memory) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 183 | goto retry_servicing; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 184 | } |
| 185 | |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 186 | out: |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 187 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 188 | "%s: %s returning: %d for %p.\n", |
| 189 | __func__, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 190 | op_name, |
| 191 | ret, |
| 192 | op); |
| 193 | return ret; |
| 194 | } |
| 195 | |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 196 | /* This can get called on an I/O op if it had a bad service_operation. */ |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 197 | bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op) |
| 198 | { |
| 199 | u64 tag = op->tag; |
| 200 | if (!op_state_in_progress(op)) |
| 201 | return false; |
| 202 | |
| 203 | op->slot_to_free = op->upcall.req.io.buf_index; |
| 204 | memset(&op->upcall, 0, sizeof(op->upcall)); |
| 205 | memset(&op->downcall, 0, sizeof(op->downcall)); |
| 206 | op->upcall.type = ORANGEFS_VFS_OP_CANCEL; |
| 207 | op->upcall.req.cancel.op_tag = tag; |
| 208 | op->downcall.type = ORANGEFS_VFS_OP_INVALID; |
| 209 | op->downcall.status = -1; |
| 210 | orangefs_new_tag(op); |
| 211 | |
| 212 | spin_lock(&orangefs_request_list_lock); |
| 213 | /* orangefs_request_list_lock is enough of a barrier here */ |
| 214 | if (!__is_daemon_in_service()) { |
| 215 | spin_unlock(&orangefs_request_list_lock); |
| 216 | return false; |
| 217 | } |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 218 | spin_lock(&op->lock); |
| 219 | set_op_state_waiting(op); |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 220 | gossip_debug(GOSSIP_DEV_DEBUG, |
| 221 | "%s: op:%s: op_state:%d: process:%s:\n", |
| 222 | __func__, |
| 223 | get_opname_string(op), |
| 224 | op->op_state, |
| 225 | current->comm); |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame] | 226 | list_add(&op->list, &orangefs_request_list); |
| 227 | spin_unlock(&op->lock); |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 228 | spin_unlock(&orangefs_request_list_lock); |
| 229 | |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 230 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 231 | "Attempting ORANGEFS operation cancellation of tag %llu\n", |
| 232 | llu(tag)); |
| 233 | return true; |
| 234 | } |
| 235 | |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 236 | /* |
| 237 | * Change an op to the "given up" state and remove it from its list. |
| 238 | */ |
| 239 | static void |
| 240 | orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 241 | { |
| 242 | /* |
| 243 | * handle interrupted cases depending on what state we were in when |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 244 | * the interruption is detected. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 245 | * |
Al Viro | eab9b38 | 2016-01-23 13:09:05 -0500 | [diff] [blame] | 246 | * Called with op->lock held. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 247 | */ |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * List manipulation code elsewhere will ignore ops that |
| 251 | * have been given up upon. |
| 252 | */ |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 253 | op->op_state |= OP_VFS_STATE_GIVEN_UP; |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 254 | |
Al Viro | 05a50a5 | 2016-02-18 18:59:44 -0500 | [diff] [blame] | 255 | if (list_empty(&op->list)) { |
| 256 | /* caught copying to/from daemon */ |
| 257 | BUG_ON(op_state_serviced(op)); |
| 258 | spin_unlock(&op->lock); |
| 259 | wait_for_completion(&op->waitq); |
| 260 | } else if (op_state_waiting(op)) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 261 | /* |
| 262 | * upcall hasn't been read; remove op from upcall request |
| 263 | * list. |
| 264 | */ |
| 265 | spin_unlock(&op->lock); |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 266 | spin_lock(&orangefs_request_list_lock); |
Al Viro | 05a50a5 | 2016-02-18 18:59:44 -0500 | [diff] [blame] | 267 | list_del_init(&op->list); |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 268 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 269 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 270 | "Interrupted: Removed op %p from request_list\n", |
| 271 | op); |
| 272 | } else if (op_state_in_progress(op)) { |
| 273 | /* op must be removed from the in progress htable */ |
| 274 | spin_unlock(&op->lock); |
Martin Brandenburg | 1d50361 | 2016-08-16 11:38:14 -0400 | [diff] [blame] | 275 | spin_lock(&orangefs_htable_ops_in_progress_lock); |
Al Viro | 05a50a5 | 2016-02-18 18:59:44 -0500 | [diff] [blame] | 276 | list_del_init(&op->list); |
Martin Brandenburg | 1d50361 | 2016-08-16 11:38:14 -0400 | [diff] [blame] | 277 | spin_unlock(&orangefs_htable_ops_in_progress_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 278 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 279 | "Interrupted: Removed op %p" |
| 280 | " from htable_ops_in_progress\n", |
| 281 | op); |
Al Viro | 05a50a5 | 2016-02-18 18:59:44 -0500 | [diff] [blame] | 282 | } else { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 283 | spin_unlock(&op->lock); |
| 284 | gossip_err("interrupted operation is in a weird state 0x%x\n", |
| 285 | op->op_state); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 286 | } |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 287 | reinit_completion(&op->waitq); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 291 | * Sleeps on waitqueue waiting for matching downcall. |
| 292 | * If client-core finishes servicing, then we are good to go. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 293 | * else if client-core exits, we get woken up here, and retry with a timeout |
| 294 | * |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 295 | * When this call returns to the caller, the specified op will no |
| 296 | * longer be in either the in_progress hash table or on the request list. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 297 | * |
| 298 | * Returns 0 on success and -errno on failure |
| 299 | * Errors are: |
| 300 | * EAGAIN in case we want the caller to requeue and try again.. |
| 301 | * EINTR/EIO/ETIMEDOUT indicating we are done trying to service this |
| 302 | * operation since client-core seems to be exiting too often |
| 303 | * or if we were interrupted. |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 304 | * |
| 305 | * Returns with op->lock taken. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 306 | */ |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 307 | static int wait_for_matching_downcall(struct orangefs_kernel_op_s *op, |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 308 | long timeout, |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 309 | bool interruptible) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 310 | { |
Al Viro | 05b39a8 | 2016-02-13 11:04:19 -0500 | [diff] [blame] | 311 | long n; |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 312 | |
Mike Marshall | ca9f518 | 2016-02-26 10:21:12 -0500 | [diff] [blame] | 313 | /* |
| 314 | * There's a "schedule_timeout" inside of these wait |
| 315 | * primitives, during which the op is out of the hands of the |
| 316 | * user process that needs something done and is being |
| 317 | * manipulated by the client-core process. |
| 318 | */ |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 319 | if (interruptible) |
Mike Marshall | adcf34a | 2016-02-24 16:54:27 -0500 | [diff] [blame] | 320 | n = wait_for_completion_interruptible_timeout(&op->waitq, |
| 321 | timeout); |
Al Viro | c72f15b | 2016-02-13 10:49:24 -0500 | [diff] [blame] | 322 | else |
| 323 | n = wait_for_completion_killable_timeout(&op->waitq, timeout); |
| 324 | |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 325 | spin_lock(&op->lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 326 | |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 327 | if (op_state_serviced(op)) |
| 328 | return 0; |
| 329 | |
| 330 | if (unlikely(n < 0)) { |
| 331 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 332 | "%s: operation interrupted, tag %llu, %p\n", |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 333 | __func__, |
| 334 | llu(op->tag), |
| 335 | op); |
| 336 | return -EINTR; |
| 337 | } |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 338 | if (op_state_purged(op)) { |
| 339 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 340 | "%s: operation purged, tag %llu, %p, %d\n", |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 341 | __func__, |
| 342 | llu(op->tag), |
| 343 | op, |
| 344 | op->attempts); |
| 345 | return (op->attempts < ORANGEFS_PURGE_RETRY_COUNT) ? |
| 346 | -EAGAIN : |
| 347 | -EIO; |
| 348 | } |
| 349 | /* must have timed out, then... */ |
| 350 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Mike Marshall | 9d9e7ba | 2016-03-03 13:46:48 -0500 | [diff] [blame] | 351 | "%s: operation timed out, tag %llu, %p, %d)\n", |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 352 | __func__, |
| 353 | llu(op->tag), |
| 354 | op, |
| 355 | op->attempts); |
| 356 | return -ETIMEDOUT; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 357 | } |