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