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 | ade3d78 | 2016-01-21 22:58:58 -0500 | [diff] [blame] | 19 | static int wait_for_matching_downcall(struct orangefs_kernel_op_s *); |
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 | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 40 | } |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 41 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 45 | * submits a ORANGEFS operation and waits for it to complete |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 46 | * |
| 47 | * Note op->downcall.status will contain the status of the operation (in |
| 48 | * errno format), whether provided by pvfs2-client or a result of failure to |
| 49 | * service the operation. If the caller wishes to distinguish, then |
| 50 | * op->state can be checked to see if it was serviced or not. |
| 51 | * |
| 52 | * Returns contents of op->downcall.status for convenience |
| 53 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 54 | int service_operation(struct orangefs_kernel_op_s *op, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 55 | const char *op_name, |
| 56 | int flags) |
| 57 | { |
| 58 | /* flags to modify behavior */ |
| 59 | sigset_t orig_sigset; |
| 60 | int ret = 0; |
| 61 | |
Mike Marshall | ce6c414 | 2015-12-14 14:54:46 -0500 | [diff] [blame] | 62 | DEFINE_WAIT(wait_entry); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 63 | |
| 64 | op->upcall.tgid = current->tgid; |
| 65 | op->upcall.pid = current->pid; |
| 66 | |
| 67 | retry_servicing: |
| 68 | op->downcall.status = 0; |
| 69 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 70 | "orangefs: service_operation: %s %p\n", |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 71 | op_name, |
| 72 | op); |
| 73 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 74 | "orangefs: operation posted by process: %s, pid: %i\n", |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 75 | current->comm, |
| 76 | current->pid); |
| 77 | |
| 78 | /* mask out signals if this operation is not to be interrupted */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 79 | if (!(flags & ORANGEFS_OP_INTERRUPTIBLE)) |
Richard Weinberger | c146c0b | 2016-01-02 23:04:47 +0100 | [diff] [blame] | 80 | orangefs_block_signals(&orig_sigset); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 81 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 82 | if (!(flags & ORANGEFS_OP_NO_SEMAPHORE)) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 83 | ret = mutex_lock_interruptible(&request_mutex); |
| 84 | /* |
| 85 | * check to see if we were interrupted while waiting for |
| 86 | * semaphore |
| 87 | */ |
| 88 | if (ret < 0) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 89 | if (!(flags & ORANGEFS_OP_INTERRUPTIBLE)) |
Richard Weinberger | c146c0b | 2016-01-02 23:04:47 +0100 | [diff] [blame] | 90 | orangefs_set_signals(&orig_sigset); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 91 | op->downcall.status = ret; |
| 92 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 93 | "orangefs: service_operation interrupted.\n"); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | } |
| 97 | |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame^] | 98 | /* queue up the operation */ |
| 99 | spin_lock(&orangefs_request_list_lock); |
| 100 | spin_lock(&op->lock); |
| 101 | set_op_state_waiting(op); |
| 102 | if (flags & ORANGEFS_OP_PRIORITY) |
| 103 | list_add(&op->list, &orangefs_request_list); |
| 104 | else |
| 105 | list_add_tail(&op->list, &orangefs_request_list); |
| 106 | spin_unlock(&op->lock); |
| 107 | wake_up_interruptible(&orangefs_request_list_waitq); |
| 108 | if (!__is_daemon_in_service()) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 109 | /* |
| 110 | * By incrementing the per-operation attempt counter, we |
| 111 | * directly go into the timeout logic while waiting for |
| 112 | * the matching downcall to be read |
| 113 | */ |
| 114 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame^] | 115 | "%s:client core is NOT in service.\n", |
| 116 | __func__); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 117 | op->attempts++; |
| 118 | } |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame^] | 119 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 120 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 121 | if (!(flags & ORANGEFS_OP_NO_SEMAPHORE)) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 122 | mutex_unlock(&request_mutex); |
| 123 | |
| 124 | /* |
| 125 | * If we are asked to service an asynchronous operation from |
| 126 | * VFS perspective, we are done. |
| 127 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 128 | if (flags & ORANGEFS_OP_ASYNC) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 129 | return 0; |
| 130 | |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 131 | ret = wait_for_matching_downcall(op); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 132 | |
| 133 | if (ret < 0) { |
| 134 | /* failed to get matching downcall */ |
| 135 | if (ret == -ETIMEDOUT) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 136 | gossip_err("orangefs: %s -- wait timed out; aborting attempt.\n", |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 137 | op_name); |
| 138 | } |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 139 | orangefs_clean_up_interrupted_operation(op); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 140 | op->downcall.status = ret; |
| 141 | } else { |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 142 | spin_unlock(&op->lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 143 | /* got matching downcall; make sure status is in errno format */ |
| 144 | op->downcall.status = |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 145 | orangefs_normalize_to_errno(op->downcall.status); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 146 | ret = op->downcall.status; |
| 147 | } |
| 148 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 149 | if (!(flags & ORANGEFS_OP_INTERRUPTIBLE)) |
Richard Weinberger | c146c0b | 2016-01-02 23:04:47 +0100 | [diff] [blame] | 150 | orangefs_set_signals(&orig_sigset); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 151 | |
| 152 | BUG_ON(ret != op->downcall.status); |
| 153 | /* retry if operation has not been serviced and if requested */ |
| 154 | if (!op_state_serviced(op) && op->downcall.status == -EAGAIN) { |
| 155 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 156 | "orangefs: tag %llu (%s)" |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 157 | " -- operation to be retried (%d attempt)\n", |
| 158 | llu(op->tag), |
| 159 | op_name, |
| 160 | op->attempts + 1); |
| 161 | |
| 162 | if (!op->uses_shared_memory) |
| 163 | /* |
| 164 | * this operation doesn't use the shared memory |
| 165 | * system |
| 166 | */ |
| 167 | goto retry_servicing; |
| 168 | |
| 169 | /* op uses shared memory */ |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame] | 170 | if (orangefs_get_bufmap_init() == 0) { |
Mike Marshall | 6ebcc3f | 2016-02-04 16:28:31 -0500 | [diff] [blame] | 171 | WARN_ON(1); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 172 | /* |
| 173 | * This operation uses the shared memory system AND |
| 174 | * the system is not yet ready. This situation occurs |
| 175 | * when the client-core is restarted AND there were |
| 176 | * operations waiting to be processed or were already |
| 177 | * in process. |
| 178 | */ |
| 179 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 180 | "uses_shared_memory is true.\n"); |
| 181 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 182 | "Client core in-service status(%d).\n", |
| 183 | is_daemon_in_service()); |
| 184 | gossip_debug(GOSSIP_WAIT_DEBUG, "bufmap_init:%d.\n", |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame] | 185 | orangefs_get_bufmap_init()); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 186 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 187 | "operation's status is 0x%0x.\n", |
| 188 | op->op_state); |
| 189 | |
| 190 | /* |
| 191 | * let process sleep for a few seconds so shared |
| 192 | * memory system can be initialized. |
| 193 | */ |
Mike Marshall | ce6c414 | 2015-12-14 14:54:46 -0500 | [diff] [blame] | 194 | prepare_to_wait(&orangefs_bufmap_init_waitq, |
| 195 | &wait_entry, |
| 196 | TASK_INTERRUPTIBLE); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 197 | |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 198 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 199 | * Wait for orangefs_bufmap_initialize() to wake me up |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 200 | * within the allotted time. |
| 201 | */ |
Al Viro | 727cbfe | 2016-01-23 13:17:55 -0500 | [diff] [blame] | 202 | ret = schedule_timeout( |
| 203 | ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS * HZ); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 204 | |
| 205 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 206 | "Value returned from schedule_timeout:" |
| 207 | "%d.\n", |
| 208 | ret); |
| 209 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 210 | "Is shared memory available? (%d).\n", |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame] | 211 | orangefs_get_bufmap_init()); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 212 | |
Mike Marshall | ce6c414 | 2015-12-14 14:54:46 -0500 | [diff] [blame] | 213 | finish_wait(&orangefs_bufmap_init_waitq, &wait_entry); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 214 | |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame] | 215 | if (orangefs_get_bufmap_init() == 0) { |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 216 | gossip_err("%s:The shared memory system has not started in %d seconds after the client core restarted. Aborting user's request(%s).\n", |
| 217 | __func__, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 218 | ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS, |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 219 | get_opname_string(op)); |
| 220 | return -EIO; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Return to the calling function and re-populate a |
| 225 | * shared memory buffer. |
| 226 | */ |
| 227 | return -EAGAIN; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | gossip_debug(GOSSIP_WAIT_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 232 | "orangefs: service_operation %s returning: %d for %p.\n", |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 233 | op_name, |
| 234 | ret, |
| 235 | op); |
| 236 | return ret; |
| 237 | } |
| 238 | |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 239 | bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op) |
| 240 | { |
| 241 | u64 tag = op->tag; |
| 242 | if (!op_state_in_progress(op)) |
| 243 | return false; |
| 244 | |
| 245 | op->slot_to_free = op->upcall.req.io.buf_index; |
| 246 | memset(&op->upcall, 0, sizeof(op->upcall)); |
| 247 | memset(&op->downcall, 0, sizeof(op->downcall)); |
| 248 | op->upcall.type = ORANGEFS_VFS_OP_CANCEL; |
| 249 | op->upcall.req.cancel.op_tag = tag; |
| 250 | op->downcall.type = ORANGEFS_VFS_OP_INVALID; |
| 251 | op->downcall.status = -1; |
| 252 | orangefs_new_tag(op); |
| 253 | |
| 254 | spin_lock(&orangefs_request_list_lock); |
| 255 | /* orangefs_request_list_lock is enough of a barrier here */ |
| 256 | if (!__is_daemon_in_service()) { |
| 257 | spin_unlock(&orangefs_request_list_lock); |
| 258 | return false; |
| 259 | } |
Al Viro | 98815ad | 2016-02-13 10:38:23 -0500 | [diff] [blame^] | 260 | spin_lock(&op->lock); |
| 261 | set_op_state_waiting(op); |
| 262 | list_add(&op->list, &orangefs_request_list); |
| 263 | spin_unlock(&op->lock); |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 264 | spin_unlock(&orangefs_request_list_lock); |
| 265 | |
| 266 | gossip_debug(GOSSIP_UTILS_DEBUG, |
| 267 | "Attempting ORANGEFS operation cancellation of tag %llu\n", |
| 268 | llu(tag)); |
| 269 | return true; |
| 270 | } |
| 271 | |
Al Viro | e07db0a | 2016-01-21 22:21:41 -0500 | [diff] [blame] | 272 | static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 273 | { |
| 274 | /* |
| 275 | * handle interrupted cases depending on what state we were in when |
| 276 | * the interruption is detected. there is a coarse grained lock |
| 277 | * across the operation. |
| 278 | * |
Al Viro | eab9b38 | 2016-01-23 13:09:05 -0500 | [diff] [blame] | 279 | * Called with op->lock held. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 280 | */ |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 281 | op->op_state |= OP_VFS_STATE_GIVEN_UP; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 282 | |
| 283 | if (op_state_waiting(op)) { |
| 284 | /* |
| 285 | * upcall hasn't been read; remove op from upcall request |
| 286 | * list. |
| 287 | */ |
| 288 | spin_unlock(&op->lock); |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 289 | spin_lock(&orangefs_request_list_lock); |
| 290 | list_del(&op->list); |
| 291 | spin_unlock(&orangefs_request_list_lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 292 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 293 | "Interrupted: Removed op %p from request_list\n", |
| 294 | op); |
| 295 | } else if (op_state_in_progress(op)) { |
| 296 | /* op must be removed from the in progress htable */ |
| 297 | spin_unlock(&op->lock); |
| 298 | spin_lock(&htable_ops_in_progress_lock); |
| 299 | list_del(&op->list); |
| 300 | spin_unlock(&htable_ops_in_progress_lock); |
| 301 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 302 | "Interrupted: Removed op %p" |
| 303 | " from htable_ops_in_progress\n", |
| 304 | op); |
| 305 | } else if (!op_state_serviced(op)) { |
| 306 | spin_unlock(&op->lock); |
| 307 | gossip_err("interrupted operation is in a weird state 0x%x\n", |
| 308 | op->op_state); |
Mike Marshall | 84d0215 | 2015-07-28 13:27:51 -0400 | [diff] [blame] | 309 | } else { |
| 310 | /* |
| 311 | * It is not intended for execution to flow here, |
| 312 | * but having this unlock here makes sparse happy. |
| 313 | */ |
| 314 | gossip_err("%s: can't get here.\n", __func__); |
| 315 | spin_unlock(&op->lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 316 | } |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 317 | reinit_completion(&op->waitq); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* |
| 321 | * sleeps on waitqueue waiting for matching downcall. |
| 322 | * if client-core finishes servicing, then we are good to go. |
| 323 | * else if client-core exits, we get woken up here, and retry with a timeout |
| 324 | * |
| 325 | * Post when this call returns to the caller, the specified op will no |
| 326 | * longer be on any list or htable. |
| 327 | * |
| 328 | * Returns 0 on success and -errno on failure |
| 329 | * Errors are: |
| 330 | * EAGAIN in case we want the caller to requeue and try again.. |
| 331 | * EINTR/EIO/ETIMEDOUT indicating we are done trying to service this |
| 332 | * operation since client-core seems to be exiting too often |
| 333 | * or if we were interrupted. |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 334 | * |
| 335 | * Returns with op->lock taken. |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 336 | */ |
Al Viro | b7ae37b | 2016-01-21 22:58:58 -0500 | [diff] [blame] | 337 | static int wait_for_matching_downcall(struct orangefs_kernel_op_s *op) |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 338 | { |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 339 | long timeout, n; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 340 | |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 341 | timeout = op->attempts ? op_timeout_secs * HZ : MAX_SCHEDULE_TIMEOUT; |
| 342 | n = wait_for_completion_interruptible_timeout(&op->waitq, timeout); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 343 | spin_lock(&op->lock); |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 344 | |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 345 | if (op_state_serviced(op)) |
| 346 | return 0; |
| 347 | |
| 348 | if (unlikely(n < 0)) { |
| 349 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 350 | "*** %s:" |
| 351 | " operation interrupted by a signal (tag " |
| 352 | "%llu, op %p)\n", |
| 353 | __func__, |
| 354 | llu(op->tag), |
| 355 | op); |
| 356 | return -EINTR; |
| 357 | } |
| 358 | op->attempts++; |
| 359 | if (op_state_purged(op)) { |
| 360 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 361 | "*** %s:" |
| 362 | " operation purged (tag " |
| 363 | "%llu, %p, att %d)\n", |
| 364 | __func__, |
| 365 | llu(op->tag), |
| 366 | op, |
| 367 | op->attempts); |
| 368 | return (op->attempts < ORANGEFS_PURGE_RETRY_COUNT) ? |
| 369 | -EAGAIN : |
| 370 | -EIO; |
| 371 | } |
| 372 | /* must have timed out, then... */ |
| 373 | gossip_debug(GOSSIP_WAIT_DEBUG, |
| 374 | "*** %s:" |
| 375 | " operation timed out (tag" |
| 376 | " %llu, %p, att %d)\n", |
| 377 | __func__, |
| 378 | llu(op->tag), |
| 379 | op, |
| 380 | op->attempts); |
| 381 | return -ETIMEDOUT; |
Mike Marshall | 1182fca | 2015-07-17 10:38:15 -0400 | [diff] [blame] | 382 | } |