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