1717#include "orangefs-bufmap.h"
1818
1919static 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 */
363369static 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