Skip to content

Commit d2d87a3

Browse files
Al Virohubcapsc
authored andcommitted
orangefs: get rid of loop in wait_for_matching_downcall()
turn op->waitq into struct completion... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Mike Marshall <hubcap@omnibond.com>
1 parent cf22644 commit d2d87a3

3 files changed

Lines changed: 49 additions & 88 deletions

File tree

‎fs/orangefs/orangefs-cache.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct orangefs_kernel_op_s *op_alloc(__s32 type)
118118
if (new_op) {
119119
INIT_LIST_HEAD(&new_op->list);
120120
spin_lock_init(&new_op->lock);
121-
init_waitqueue_head(&new_op->waitq);
121+
init_completion(&new_op->waitq);
122122

123123
atomic_set(&new_op->ref_count, 1);
124124

‎fs/orangefs/orangefs-kernel.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct orangefs_kernel_op_s {
202202
struct orangefs_upcall_s upcall;
203203
struct orangefs_downcall_s downcall;
204204

205-
wait_queue_head_t waitq;
205+
struct completion waitq;
206206
spinlock_t lock;
207207

208208
struct completion done;
@@ -222,7 +222,7 @@ struct orangefs_kernel_op_s {
222222
static inline void set_op_state_serviced(struct orangefs_kernel_op_s *op)
223223
{
224224
op->op_state = OP_VFS_STATE_SERVICED;
225-
wake_up_interruptible(&op->waitq);
225+
complete(&op->waitq);
226226
}
227227

228228
#define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING)
@@ -266,7 +266,7 @@ static inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
266266
put_cancel(op);
267267
} else {
268268
op->op_state |= OP_VFS_STATE_PURGED;
269-
wake_up_interruptible(&op->waitq);
269+
complete(&op->waitq);
270270
spin_unlock(&op->lock);
271271
}
272272
}

‎fs/orangefs/waitqueue.c‎

Lines changed: 45 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "orangefs-bufmap.h"
1818

1919
static int wait_for_matching_downcall(struct orangefs_kernel_op_s *);
20+
static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *);
2021

2122
/*
2223
* What we do in this function is to walk the list of operations that are
@@ -170,8 +171,10 @@ int service_operation(struct orangefs_kernel_op_s *op,
170171
gossip_err("orangefs: %s -- wait timed out; aborting attempt.\n",
171172
op_name);
172173
}
174+
orangefs_clean_up_interrupted_operation(op);
173175
op->downcall.status = ret;
174176
} else {
177+
spin_unlock(&op->lock);
175178
/* got matching downcall; make sure status is in errno format */
176179
op->downcall.status =
177180
orangefs_normalize_to_errno(op->downcall.status);
@@ -343,6 +346,7 @@ static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s
343346
gossip_err("%s: can't get here.\n", __func__);
344347
spin_unlock(&op->lock);
345348
}
349+
reinit_completion(&op->waitq);
346350
}
347351

348352
/*
@@ -359,95 +363,52 @@ static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s
359363
* EINTR/EIO/ETIMEDOUT indicating we are done trying to service this
360364
* operation since client-core seems to be exiting too often
361365
* or if we were interrupted.
366+
*
367+
* Returns with op->lock taken.
362368
*/
363369
static int wait_for_matching_downcall(struct orangefs_kernel_op_s *op)
364370
{
365-
int ret = -EINVAL;
366-
DEFINE_WAIT(wait_entry);
371+
long timeout, n;
367372

368-
while (1) {
369-
spin_lock(&op->lock);
370-
prepare_to_wait(&op->waitq, &wait_entry, TASK_INTERRUPTIBLE);
371-
if (op_state_serviced(op)) {
372-
spin_unlock(&op->lock);
373-
ret = 0;
374-
break;
375-
}
373+
timeout = op->attempts ? op_timeout_secs * HZ : MAX_SCHEDULE_TIMEOUT;
374+
n = wait_for_completion_interruptible_timeout(&op->waitq, timeout);
375+
spin_lock(&op->lock);
376376

377-
if (unlikely(signal_pending(current))) {
378-
gossip_debug(GOSSIP_WAIT_DEBUG,
379-
"*** %s:"
380-
" operation interrupted by a signal (tag "
381-
"%llu, op %p)\n",
382-
__func__,
383-
llu(op->tag),
384-
op);
385-
orangefs_clean_up_interrupted_operation(op);
386-
ret = -EINTR;
387-
break;
388-
}
377+
if (op_state_serviced(op))
378+
return 0;
389379

390-
/*
391-
* if this was our first attempt and client-core
392-
* has not purged our operation, we are happy to
393-
* simply wait
394-
*/
395-
if (op->attempts == 0 && !op_state_purged(op)) {
396-
spin_unlock(&op->lock);
397-
schedule();
398-
} else {
399-
spin_unlock(&op->lock);
400-
/*
401-
* subsequent attempts, we retry exactly once
402-
* with timeouts
403-
*/
404-
if (!schedule_timeout(op_timeout_secs * HZ)) {
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-
ret = -ETIMEDOUT;
414-
spin_lock(&op->lock);
415-
orangefs_clean_up_interrupted_operation(op);
416-
break;
417-
}
418-
}
419-
spin_lock(&op->lock);
420-
op->attempts++;
421-
/*
422-
* if the operation was purged in the meantime, it
423-
* is better to requeue it afresh but ensure that
424-
* we have not been purged repeatedly. This could
425-
* happen if client-core crashes when an op
426-
* is being serviced, so we requeue the op, client
427-
* core crashes again so we requeue the op, client
428-
* core starts, and so on...
429-
*/
430-
if (op_state_purged(op)) {
431-
ret = (op->attempts < ORANGEFS_PURGE_RETRY_COUNT) ?
432-
-EAGAIN :
433-
-EIO;
434-
gossip_debug(GOSSIP_WAIT_DEBUG,
435-
"*** %s:"
436-
" operation purged (tag "
437-
"%llu, %p, att %d)\n",
438-
__func__,
439-
llu(op->tag),
440-
op,
441-
op->attempts);
442-
orangefs_clean_up_interrupted_operation(op);
443-
break;
444-
}
445-
spin_unlock(&op->lock);
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;
446389
}
447-
448-
spin_lock(&op->lock);
449-
finish_wait(&op->waitq, &wait_entry);
450-
spin_unlock(&op->lock);
451-
452-
return ret;
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;
453414
}

0 commit comments

Comments
 (0)