@@ -43,9 +43,7 @@ static void orangefs_devreq_add_op(struct orangefs_kernel_op_s *op)
4343{
4444 int index = hash_func (op -> tag , hash_table_size );
4545
46- spin_lock (& htable_ops_in_progress_lock );
4746 list_add_tail (& op -> list , & htable_ops_in_progress [index ]);
48- spin_unlock (& htable_ops_in_progress_lock );
4947}
5048
5149static struct orangefs_kernel_op_s * orangefs_devreq_remove_op (__u64 tag )
@@ -60,8 +58,9 @@ static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
6058 next ,
6159 & htable_ops_in_progress [index ],
6260 list ) {
63- if (op -> tag == tag ) {
64- list_del (& op -> list );
61+ if (op -> tag == tag && !op_state_purged (op )) {
62+ list_del_init (& op -> list );
63+ get_op (op ); /* increase ref count. */
6564 spin_unlock (& htable_ops_in_progress_lock );
6665 return op ;
6766 }
@@ -127,12 +126,17 @@ static ssize_t orangefs_devreq_read(struct file *file,
127126 return - EINVAL ;
128127 }
129128
129+ restart :
130130 /* Get next op (if any) from top of list. */
131131 spin_lock (& orangefs_request_list_lock );
132132 list_for_each_entry_safe (op , temp , & orangefs_request_list , list ) {
133133 __s32 fsid ;
134134 /* This lock is held past the end of the loop when we break. */
135135 spin_lock (& op -> lock );
136+ if (unlikely (op_state_purged (op ))) {
137+ spin_unlock (& op -> lock );
138+ continue ;
139+ }
136140
137141 fsid = fsid_of_op (op );
138142 if (fsid != ORANGEFS_FS_ID_NULL ) {
@@ -197,16 +201,10 @@ static ssize_t orangefs_devreq_read(struct file *file,
197201 spin_unlock (& orangefs_request_list_lock );
198202 return - EAGAIN ;
199203 }
200-
201- /*
202- * Set the operation to be in progress and move it between lists since
203- * it has been sent to the client.
204- */
205- set_op_state_inprogress (cur_op );
206-
207- list_del (& cur_op -> list );
204+ list_del_init (& cur_op -> list );
205+ get_op (op );
208206 spin_unlock (& orangefs_request_list_lock );
209- orangefs_devreq_add_op ( cur_op );
207+
210208 spin_unlock (& cur_op -> lock );
211209
212210 /* Push the upcall out. */
@@ -224,6 +222,25 @@ static ssize_t orangefs_devreq_read(struct file *file,
224222 if (ret != 0 )
225223 goto error ;
226224
225+ spin_lock (& htable_ops_in_progress_lock );
226+ spin_lock (& cur_op -> lock );
227+ if (unlikely (op_state_given_up (cur_op ))) {
228+ spin_unlock (& cur_op -> lock );
229+ spin_unlock (& htable_ops_in_progress_lock );
230+ op_release (cur_op );
231+ goto restart ;
232+ }
233+
234+ /*
235+ * Set the operation to be in progress and move it between lists since
236+ * it has been sent to the client.
237+ */
238+ set_op_state_inprogress (cur_op );
239+ orangefs_devreq_add_op (cur_op );
240+ spin_unlock (& cur_op -> lock );
241+ spin_unlock (& htable_ops_in_progress_lock );
242+ op_release (cur_op );
243+
227244 /* The client only asks to read one size buffer. */
228245 return MAX_DEV_REQ_UPSIZE ;
229246error :
@@ -235,11 +252,13 @@ static ssize_t orangefs_devreq_read(struct file *file,
235252 gossip_err ("orangefs: Failed to copy data to user space\n" );
236253 spin_lock (& orangefs_request_list_lock );
237254 spin_lock (& cur_op -> lock );
238- set_op_state_waiting (cur_op );
239- orangefs_devreq_remove_op (cur_op -> tag );
240- list_add (& cur_op -> list , & orangefs_request_list );
255+ if (likely (!op_state_given_up (cur_op ))) {
256+ set_op_state_waiting (cur_op );
257+ list_add (& cur_op -> list , & orangefs_request_list );
258+ }
241259 spin_unlock (& cur_op -> lock );
242260 spin_unlock (& orangefs_request_list_lock );
261+ op_release (cur_op );
243262 return - EFAULT ;
244263}
245264
@@ -278,15 +297,13 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
278297 __func__ ,
279298 total ,
280299 (unsigned int ) MAX_DEV_REQ_DOWNSIZE );
281- ret = - EFAULT ;
282- goto out ;
300+ return - EFAULT ;
283301 }
284302
285303 n = copy_from_iter (& head , head_size , iter );
286304 if (n < head_size ) {
287305 gossip_err ("%s: failed to copy head.\n" , __func__ );
288- ret = - EFAULT ;
289- goto out ;
306+ return - EFAULT ;
290307 }
291308
292309 if (head .version < ORANGEFS_MINIMUM_USERSPACE_VERSION ) {
@@ -295,31 +312,26 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
295312 __func__ ,
296313 head .version ,
297314 ORANGEFS_MINIMUM_USERSPACE_VERSION );
298- ret = - EPROTO ;
299- goto out ;
315+ return - EPROTO ;
300316 }
301317
302318 if (head .magic != ORANGEFS_DEVREQ_MAGIC ) {
303319 gossip_err ("Error: Device magic number does not match.\n" );
304- ret = - EPROTO ;
305- goto out ;
320+ return - EPROTO ;
306321 }
307322
308323 op = orangefs_devreq_remove_op (head .tag );
309324 if (!op ) {
310325 gossip_err ("WARNING: No one's waiting for tag %llu\n" ,
311326 llu (head .tag ));
312- goto out ;
327+ return ret ;
313328 }
314329
315- get_op (op ); /* increase ref count. */
316-
317330 n = copy_from_iter (& op -> downcall , downcall_size , iter );
318331 if (n != downcall_size ) {
319332 gossip_err ("%s: failed to copy downcall.\n" , __func__ );
320- put_op (op );
321333 ret = - EFAULT ;
322- goto out ;
334+ goto Broken ;
323335 }
324336
325337 if (op -> downcall .status )
@@ -339,9 +351,8 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
339351 downcall_size ,
340352 op -> downcall .trailer_size ,
341353 total );
342- put_op (op );
343354 ret = - EFAULT ;
344- goto out ;
355+ goto Broken ;
345356 }
346357
347358 /* Only READDIR operations should have trailers. */
@@ -350,9 +361,8 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
350361 gossip_err ("%s: %x operation with trailer." ,
351362 __func__ ,
352363 op -> downcall .type );
353- put_op (op );
354364 ret = - EFAULT ;
355- goto out ;
365+ goto Broken ;
356366 }
357367
358368 /* READDIR operations should always have trailers. */
@@ -361,9 +371,8 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
361371 gossip_err ("%s: %x operation with no trailer." ,
362372 __func__ ,
363373 op -> downcall .type );
364- put_op (op );
365374 ret = - EFAULT ;
366- goto out ;
375+ goto Broken ;
367376 }
368377
369378 if (op -> downcall .type != ORANGEFS_VFS_OP_READDIR )
@@ -374,9 +383,8 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
374383 if (op -> downcall .trailer_buf == NULL ) {
375384 gossip_err ("%s: failed trailer vmalloc.\n" ,
376385 __func__ );
377- put_op (op );
378386 ret = - ENOMEM ;
379- goto out ;
387+ goto Broken ;
380388 }
381389 memset (op -> downcall .trailer_buf , 0 , op -> downcall .trailer_size );
382390 n = copy_from_iter (op -> downcall .trailer_buf ,
@@ -385,9 +393,8 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
385393 if (n != op -> downcall .trailer_size ) {
386394 gossip_err ("%s: failed to copy trailer.\n" , __func__ );
387395 vfree (op -> downcall .trailer_buf );
388- put_op (op );
389396 ret = - EFAULT ;
390- goto out ;
397+ goto Broken ;
391398 }
392399
393400wakeup :
@@ -404,15 +411,15 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
404411 * the buffers are done being used.
405412 */
406413 if (op -> downcall .type == ORANGEFS_VFS_OP_FILE_IO ) {
407- int timed_out = 0 ;
408414 DEFINE_WAIT (wait_entry );
409415
410416 /*
411417 * tell the vfs op waiting on a waitqueue
412418 * that this op is done
413419 */
414420 spin_lock (& op -> lock );
415- set_op_state_serviced (op );
421+ if (!op_state_given_up (op ))
422+ set_op_state_serviced (op );
416423 spin_unlock (& op -> lock );
417424
418425 while (1 ) {
@@ -435,7 +442,6 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
435442 gossip_debug (GOSSIP_DEV_DEBUG ,
436443 "%s: timed out.\n" ,
437444 __func__ );
438- timed_out = 1 ;
439445 break ;
440446 }
441447 continue ;
@@ -450,15 +456,6 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
450456 spin_lock (& op -> lock );
451457 finish_wait (& op -> io_completion_waitq , & wait_entry );
452458 spin_unlock (& op -> lock );
453-
454- /* NOTE: for I/O operations we handle releasing the op
455- * object except in the case of timeout. the reason we
456- * can't free the op in timeout cases is that the op
457- * service logic in the vfs retries operations using
458- * the same op ptr, thus it can't be freed.
459- */
460- if (!timed_out )
461- op_release (op );
462459 } else {
463460 /*
464461 * tell the vfs op waiting on a waitqueue that
@@ -468,11 +465,22 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
468465 * notification
469466 */
470467 spin_lock (& op -> lock );
471- set_op_state_serviced (op );
468+ if (!op_state_given_up (op ))
469+ set_op_state_serviced (op );
472470 spin_unlock (& op -> lock );
473471 }
474472out :
473+ op_release (op );
475474 return ret ;
475+
476+ Broken :
477+ spin_lock (& op -> lock );
478+ if (!op_state_given_up (op )) {
479+ op -> downcall .status = ret ;
480+ set_op_state_serviced (op );
481+ }
482+ spin_unlock (& op -> lock );
483+ goto out ;
476484}
477485
478486/* Returns whether any FS are still pending remounted */
0 commit comments